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】


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM