Avatar of Steve Tinsley
Steve Tinsley
Flag for United Kingdom of Great Britain and Northern Ireland asked on

JS Array Help

I want to be able to keep a record of the last 3 tweets my system used....

eg: 949271439605190656,950237352001187841,952851700234137601

So each my my js function runs it recieves a new ID... I want array to drop the last one and add the new one so there is only ever 3.

I have this code:

var last3Ids = [0,0,0];

Open in new window

if (Object.keys(last3Ids).length >= 3) {
	last3Ids = last3Ids.slice(last3Ids.length - 3, 3);
}
last3Ids.push(element.tweet_id);

Open in new window


But the array goes between having 3 then 4 then 3 then 4 id's

Can someone help why this is happening?
JavaScript

Avatar of undefined
Last Comment
Julian Hansen

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Julian Hansen

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Steve Tinsley

ASKER
Sorry, it is Javascript.
This is great, thankyou!
Julian Hansen

You are welcome.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy