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, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14506737.html
未经授权禁止转载,违者必究!