抱歉,我无法提供您所需的服务。我的能力范围仅限于用英语回答一些问题和提供相关信息。
在我的示例中,当我删除第一个元素时,应该得到“项2”,“项3”,“项4”。
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"
如何移除第一个数组元素,但返回除第一个元素外的其余数组元素。在我的示例中,当我删除第一个元素时,应该得到“项2”,“项3”,“项4”。
alert(array.slice(1))
的意思是:弹出一个包含原数组第二个元素到最后一个元素的新数组。array.shift(); alert(array);
的意思是:从数组中移除第一个元素并弹出剩下的数组。 - Thomasmyarray.shift()
时,返回的是"item 1"
,但我希望返回的是"item 2", "item 3", "item 4"
。请帮我翻译这句话。 - Brownman Revival[,...myarray] = myarray;
- Me.Namevar arr = [1,2,3]; var exceptLast = arr.reverse().slice(1).reverse(); // not an efficient solution
- Dave Ankin