jquery 去掉重复项(splice,apply,push)

 1 /*
 2 js数组去掉重复项
 3 var somearray = [1,1,2,2,3,3,4,4,'1'];
 4 somearray.check();
 5 //somearray will return arr=[1,2,3,4,'1']
 6 */
 7 Array.prototype.check= function(){
 8 var tem=[];
 9 this.forEach(function(value){
10 if(tem.indexOf(value)===-1){
11 tem.push(value);
12 }
13 });
14 this.splice(0);
15 this.push.apply(this,tem);
16 }

 注:与数字相同的数字字符无法区分,比如【'1'】和【1】

原文地址:https://www.cnblogs.com/wu-peng/p/5566070.html