📌  相关文章
📜  lodash 删除不在数组中 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:05.438000             🧑  作者: Mango

代码示例4
var a = [
  {id: 1, name: 'A'},
  {id: 2, name: 'B'},
  {id: 3,  name: 'C'},
  {id: 4, name: 'D'}
];
var removeItem = [1,2];
removeItem.forEach(function(id){
   var itemIndex = a.findIndex(i => i.id == id);
   a.splice(itemIndex,1);
});
console.log(a);