Remove Items from an Array with pop() and shift()

Опубликовано: 06 Октябрь 2024
на канале: HighTech6839v
16
0

What does shift() do in JavaScript? The shift() method removes the first item of an array. The shift() method changes the original array.

What does pop() do in JavaScript? The pop() method removes the last element from an array and returns that value to the caller. If you call pop() on an empty array, it returns undefined . Array.prototype.shift() has similar behavior to pop() , but applied to the first element in an array.