var myarray = ["item 1", "item 2", "item 3", "item 4"];
//removes the first element of the array, and returns that element.
alert(myarray.shift());
//alerts "item 1"
//removes the last element of the array, and returns that element.
alert(myarray.pop());
//alerts "item 4"
- How to remove the first array but return the array minus the first element
- In my example i should get
"item 2", "item 3", "item 4"
when i remove the first element
alert(array.slice(1))
orarray.shift(); alert(array);
myarray.shift()
returns"item 1"
what i want is return"item 2", "item 3", "item 4"
shift()
[,...myarray] = myarray;