方法1:let array = [{id:1,name:'a'},{id:2,name:'b'},{id:3,name:'c},{id:4,name:'d'}]
let id= 3;
var newArray = array.filter(function (item) {
if(id != item.id ){
return item
}
})
console.log(newArray )方法2:let array = [{id:1,name:'a'},{id:2,name:'b'},{id:3,name:'c},{id:4,name:'d'}]
let id = 3;
array.forEach((item,index)=>{
if(id == item.id){
array.splice(index,1)
}
})
console.log(array)
技术
· 2023-03-24
· 260 人浏览
柚子生活