xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

js array remove item All In One

js array remove item All In One

splice

https://stackoverflow.com/a/55686164/5934465

array.splice(start[, deleteCount[, item1[, item2[, ...]]]])

splice() 方法通过删除替换现有元素或者原地添加新的元素来修改数组,并以数组形式返回被修改的内容。
此方法会改变原数组。

https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

const months = ['Jan', 'March', 'April', 'June'];

// remove last one item
months.splice(months.length - 1, 1);
// ["June"]

console.log(months);
// ["Jan", "March", "April"]


const months = ['Jan', 'March', 'April', 'June'];

// remove last one item
months.pop();
// "June"

console.log(months);
// ["Jan", "March", "April"]

refs

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop



©xgqfrms 2012-2020

www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2021-03-09 17:17  xgqfrms  阅读(87)  评论(1编辑  收藏  举报