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 ]
let arr = [1,1,2,2,3]
let handleArr=Array.from(new Set (arr));
// [ 1, 2, 3 ]
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 ]
本文标题:数组去重
本文链接:https://www.haomeiwen.com/subject/jxhouhtx.html
网友评论