Basic JavaScript (44/111) | Manipulate Arrays With shift | freeCodeCamp

Published: 07 September 2020
on channel: Stral Tech
375
1

Basic JavaScript (44/111) | Manipulate Arrays With shift | freeCodeCamp

pop() always removes the last element of an array. What if you want to remove the first?

That's where .shift() comes in. It works just like .pop(), except it removes the first element instead of the last.

Example:
var ourArray = ["Stimpson", "J", ["cat"]];
var removedFromOurArray = ourArray.shift();
// removedFromOurArray now equals "Stimpson" and ourArray now equals ["J", ["cat"]].

Use the .shift() function to remove the first item from myArray, assigning the "shifted off" value to removedFromMyArray.

https://www.freecodecamp.org/learn/ja...


On this page of the site you can watch the video online Basic JavaScript (44/111) | Manipulate Arrays With shift | freeCodeCamp with a duration of hours minute second in good quality, which was uploaded by the user Stral Tech 07 September 2020, share the link with friends and acquaintances, this video has already been watched 375 times on youtube and it was liked by 1 viewers. Enjoy your viewing!