数组去重/合并
let mgrUserList = Array.from(new Set(ROLE_PLOT_MGR.concat(ROLE_FARM_MGR).concat(ROLE_ADMIN)));
ES6中利用Set去重
此方法是所有去重方法中代码最少的方法,代码如下:
function newArr(arr){
return Array.from(new Set(arr))
}
var arr = [1,1,2,9,6,9,6,3,1,4,5];
console.log(newArr(arr))
concat–合并数组,并且不去重
var arr1 = [“ab”,“bc”,“de”,“fg”];
var arr2 = [“ml”,“kg”,“ww”,“bc”,“am”];
var arr3 = arr1.concat(arr2);
console.log(arr3)
两种方法结合就数组合并去重
let mgrUserList = Array.from(new Set(ROLE_PLOT_MGR.concat(ROLE_FARM_MGR).concat(ROLE_ADMIN)));