# 数组去重

        {
function createTestArray(){
const testArray=[1,2,3,4,5,'a','b','c','d','e'];
for(let i=0;i<13;i++){
testArray.push(...testArray);
}
testArray.sort((a,b)=>Math.random()>0.5?1:-1);
//console.log(testArray:${testArray},length:${testArray.length});
return testArray;
}
const testArray=createTestArray();

function showTime(fun){
const start=new Date();
const result=fun();
return name:${fun.name},time:${new Date()-start},result:\${result.join(',')};
}

function removeRepeatBySet(){
return [...new Set(testArray)];
}

function removeRepeatByFilter(){
return testArray.filter((item,index,arr)=>arr.indexOf(item)==index);
}

function removeRepeatByForof(){
const obj={},arr=[],value={};
for(let i of testArray){
if(obj[i]==value){
continue;
}else if(obj[i]!=value){
obj[i]=value;
arr.push(i);
}
}
return arr;
}

function removeRepeatByFor(){
const obj={},arr=[],value={};
for(let i= 0,len=testArray.length;i

[
"name:removeRepeatByFilter,time:10,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:10,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:12,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:6,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:7,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:7,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:8,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:9,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:9,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFilter,time:9,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:2,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:3,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:3,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:3,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:3,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:4,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:4,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:4,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:5,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByFor,time:6,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:11,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:6,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:6,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:7,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:8,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:8,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:8,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:9,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:9,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatByForof,time:9,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:10,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:13,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:16,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:6,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:7,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:7,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:8,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:9,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:9,result:3,5,a,b,1,4,c,2,e,d",
"name:removeRepeatBySet,time:9,result:3,5,a,b,1,4,c,2,e,d"
]

#### JavaScript Array数组去重源码下载

2017年06月29日 2KB 下载

#### JavaScript 数组去重的多种方法原理详解

2017-06-02 14:24:14

#### 数组去重的五种方法

2017-04-18 17:49:28

#### 数组去重方法大全

2016-05-15 13:19:40

#### 数组去重的方法总结

2017-05-19 08:43:35

#### js中数组去重的几种方法

2016-12-14 15:01:44

#### 五种js实现数组去重的方法

2016-03-26 16:34:40

#### 面试题——4种数组去重的方法

2017-01-05 11:38:04

#### 编写一个数组去重的方法

2017-11-12 19:00:23

#### 数组去去重的几种写法

2016-11-20 15:56:03