描述问题
总结项目中,实现数组去重的方法
reduce()方法
//表格全选
let arr = this.selectTableGrounpList.concat(selection);
let obj = {};
this.selectTableGrounpList = arr.reduce((item: any, next) => {
obj[next.userId] ? "" : (obj[next.userId] = true && item.push(next));
return item;
}, []);
new Set()方法
dealStringToArray(value) {
let selectedAppIds = [];
value.map(it => {
!it.includes("_")
? selectedAppIds.push(it)
: it.split("_").map(item => {
selectedAppIds.push(item);
});
});
return Array.from(new Set(selectedAppIds));
}
总结
简单的记录一下,有时候因为一些方法使用不当或者没有想到如何去写,导致工作效率下降,记录一下,方便以后查找以及回顾,如果对你有帮忙,记得star一下,end~~~