数组去重

1.set去重

let arr = [1,1,2,2,3]
let handleArr=Array.from(new Set (arr));

// [ 1, 2, 3 ]

Map去重

let arr = [1,1,2,2,3]
let mapObj = new Map()
let handleArr=arr.filter( (item) => !mapObj.has(item) && mapObj.set(item,"1"));

// [ 1, 2, 3 ]

你可能感兴趣的:(数组去重)