js 删除数组中指定元素
方法一:
let sourceArray = [1001, 1002, 1003, 1004, 1005]
let target = 1001 // 指定元素
sourceArray.forEach((item, index, arr) => {
if (item === target) {
arr.splice(index, 1);
}
})
方法二:
let sourceArray = [1001, 1002, 1003, 1004, 1005]
let target = 1001 // 指定元素
sourceArray = sourceArray.filter((item) => {
return item !== target
})