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

Показать описание
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"]];
// 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.
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"]];
// 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.