我想从下面的对象数组中删除所有重复的元素,并形成一个新的数组。
let arr = [{item: 'abc'},{item: 'def'},{item: 'abc'},{item: 'ghi'}];
预期输出:
let newArr = [{item: 'abc'},{item: 'def'},{item: 'ghi'}];
过滤掉前面有匹配项的条目
let arr = [{item: 'abc'},{item: 'def'},{item: 'abc'},{item: 'ghi'}];
let newArray = arr.filter((val, index) => !arr.find((val2, index2) => val.item === val2.item && index > index2));
console.log(newArray);