Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 基于另一个数组从数组中删除项_Javascript_Node.js - Fatal编程技术网

Javascript 基于另一个数组从数组中删除项

Javascript 基于另一个数组从数组中删除项,javascript,node.js,Javascript,Node.js,我正在做一个数据处理程序,我几乎完成了。我已经有了重复检测算法,我有一个包括重复项在内的所有项的列表,还有一个重复项的列表 我想浏览项目列表,按重复项列表过滤,并删除除第一个重复项以外的所有项。我试过这样做,但实际上并没有从数组中删除记录 const removeDupes = (list, dupes) => { list.forEach(listItem => { let filtered = dupes.filter(x => ((x.item1.extern

我正在做一个数据处理程序,我几乎完成了。我已经有了重复检测算法,我有一个包括重复项在内的所有项的列表,还有一个重复项的列表

我想浏览项目列表,按重复项列表过滤,并删除除第一个重复项以外的所有项。我试过这样做,但实际上并没有从数组中删除记录

const removeDupes = (list, dupes) => {
  list.forEach(listItem => {
    let filtered = dupes.filter(x => ((x.item1.externalId === listItem.externalId)|| (x.item2.externalId === listItem.externalId)));
    if(filtered.length > 0){
      for(let i = 1; i < filtered.length; i++){
        list.splice(list.indexOf(filtered[i]));
      }
    }
  });
  return list;
}

它们不是完全的副本,更像是来自不同数据库的副本,这些数据库具有不同的模式,已重新格式化为相同的模式….

我会这样做:

const noDuplicates = [...(new Set(duplicates))]; // This creates an array that removes duplicated items in it
然后将其与原始列表进行比较:

const removeDupes = list.filter(value => !noDuplicates.includes(value)); // This will add the value if it is not in the list
让我知道这是否适合你

const removeDupes = list.filter(value => !noDuplicates.includes(value)); // This will add the value if it is not in the list