Created
April 29, 2013 04:12
-
-
Save cssoul/5479661 to your computer and use it in GitHub Desktop.
去掉数组中的重复元素
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Array.prototype.strip=function() | |
{ | |
if(this.length<2) return [this[0]]||[]; | |
var arr=[]; | |
for(var i=0;i<this.length;i++) | |
{ | |
arr.push(this.splice(i--,1)); | |
for(var j=0;j<this.length;j++) | |
{ | |
if(this[j]==arr[arr.length-1]) | |
{ | |
this.splice(j--,1); | |
} | |
} | |
} | |
return arr; | |
} | |
var newArr=["abc",1,"abc",2,3,4,1,2,3]; | |
console.log(newArr.strip()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment