【发布时间】:2016-10-31 23:45:12
【问题描述】:
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"
- 如何删除第一个数组但返回减去第一个元素的数组
- 在我的示例中,当我删除第一个元素时,我应该得到
"item 2", "item 3", "item 4"
【问题讨论】:
-
alert(array.slice(1))或array.shift(); alert(array); -
@Thomas 当我使用
myarray.shift()时返回"item 1"我想要的是返回"item 2", "item 3", "item 4" -
请阅读我写的全部代码,使用
shift() -
如果您需要创建没有第一个元素的新数组,请使用切片。
-
只是再添加一个 :) 解构:
[,...myarray] = myarray;
标签: javascript jquery arrays