jQuery 删除的第一个数组元素

简单的JavaScript代码段可删除数组的第一个元素。 您也可以轻松删除数组的最后一个元素。 只需使用JavaScript array.shift()和array.pop()方法即可。 这些方法改变了数组的长度!

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"

不要忘记将您的jQuery代码放在文档就绪函数中。 有关更多信息,请参见4个不同的jQuery文档就绪示例 。

原文链接: https://www.sitepoint.com/jquery-remove-array-element/

你可能感兴趣的:(jQuery 删除的第一个数组元素)