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】