javascript - remove first element from array and return the the array minus the first element -
var myarray = ["item 1", "item 2", "item 3", "item 4"]; //removes first element of array, , returns element. alert(myarray.shift()); //alerts "item 1" //removes last element of array, , returns element. alert(myarray.pop()); //alerts "item 4"
- how remove first array return array minus first element
- in example should
"item 2", "item 3", "item 4"
when remove first element
this should remove first element, , can return remaining:
var myarray = ["item 1", "item 2", "item 3", "item 4"]; myarray.shift(); alert(myarray);
as others have suggested, use slice(1);
var myarray = ["item 1", "item 2", "item 3", "item 4"]; alert(myarray.slice(1));
Comments
Post a Comment