TreeList({ parentId: this.chuanshu }).then((res) => {
let arr1 = this.unique(res.rows.map((item) => {
return item;
})
);
this.checkboxList = arr1;
});
unique(arr) {
const res = new Map();
return arr.filter((arr) => !res.has(arr.typeId) && res.set(arr.typeId, 1));
},
针对那个去重就写那个Key值 我去的是数组里的typeId 去别的话就在unique方法里的arr后面写那个key值
本文探讨了如何使用JavaScript实现数组去重,通过unique()方法利用Map数据结构过滤重复元素。示例代码中展示了在处理包含typeId字段的数组时进行去重的操作,适用于数据处理和信息管理场景。
1603

被折叠的 条评论
为什么被折叠?



