[转]javascript删除数组项目的技巧
1. map + splice 写法
deleteInfo(recycleItem) {
this.todoInfos.map((item, index) => {
if(item.id == recycleItem.id) {
this.todoInfos.splice(index, 1);
}
})
}
2. splice + findIndex 写法
deleteInfo(recycleItem) {
this.todoInfos.splice( this.todoInfos.findIndex( v => v.id === recycleItem.id), 1);
}
3. filter 写法
deleteInfo(recycleItem) {
this.todoInfos = this.todoInfos.filter( (x) => {
return x.id != recycleItem.id;
})
}
欢迎关注小程序,感谢您的支持!