数组去重的几种方式
let originalArray = [1,2,3,4,5,3,2,4,1];// 方式1const result =Array.from( newSet(originalArray));console.log(result); // -> [1, 2, 3, 4, 5]// 方式2const result = [];const map = newMap();for (let v of originalArray ) { if ( !map.has(v)) { map.set(v,true); result.push(v); }}console.log(result);// -> [1, 2, 3, 4, 5]// 方式3const result = [];for ( let v of originalArray) {if(!result.includes(v)) { result.push(v); }}console.log(result);// -> [1, 2, 3, 4, 5]
发表评论 (审核通过后显示评论):