根据数组中的某一项的某个属性去重
var arr_1 = [
{
label:“数组1”,
value:“1”
},
{
label:“数组2”,
value:“2”
},
{
label:“数组3”,
value:“3”
},
{
label:“数组1”,
value:“1”
},
]
unique(arr, key) {
let map = new Map();
arr.forEach((item, index) => {
if (!map.has(item[key])) {
map.set(item[key], item);
}
});
return […map.values()];
}
this.unique(arr_1,“value”)