JavaScript concept with a cup of coffee and a laptop

Array Methods & Properties


Shift allows us to remove the first item in the array. It works similar to pop. Consider the following code from our baseball array we have been using…

console.log( baseballCards );

The output will be ‘Ruth’, ‘Wagner’, ‘Uecker’.

It basically removes the item and shifts everything over.

There might be times you wish to remove an item from an array, but still keep it for some usage. We can store it in a variable…

let greatHomeRunHitter = baseballCards.shift();
console.log( greatHomeRunHitter);

The output will be Aaron given our original added array.

Happy Coding!

Clay Hess

Share this post

Share on facebook
Share on google
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email
Skip to content