Javascript 从具有依赖值的重复项的数组中删除重复项
我有一个具有重复值的数组。 我需要从中删除重复项Javascript 从具有依赖值的重复项的数组中删除重复项,javascript,angular,typescript,Javascript,Angular,Typescript,我有一个具有重复值的数组。 我需要从中删除重复项 this.list1 = [ { item_id: 1, item_text: 'Maintenance' }, { item_id: 2, item_text: 'Raw Material Plates and Profile' }, { item_id: 3, item_text: 'Raw Material Plates and Profile' },
this.list1 = [
{ item_id: 1, item_text: 'Maintenance' },
{ item_id: 2, item_text: 'Raw Material Plates and Profile' },
{ item_id: 3, item_text: 'Raw Material Plates and Profile' },
{ item_id: 4, item_text: 'Asset' },
{ item_id: 5, item_text: 'Asset' },
.
.
.
]
删除重复项后
this.list1 = [
{ item_id: 1, item_text: 'Maintenance' },
{ item_id: 2, item_text: 'Raw Material Plates and Profile' },
{ item_id: 3, item_text: 'Asset' },
.
.
.
]
此外,删除重复项后,项目id应保持有序。
如何以适当的方式做到这一点
var result = this.list1.reduce((unique, o) => {
if(!unique.some(obj => obj.item_text === o.item_text)) {
unique.push(o);
}
return unique;
},[]);
console.log(result);