Skip to content

Instantly share code, notes, and snippets.

@cssoul
Created April 29, 2013 04:12
Show Gist options
  • Save cssoul/5479661 to your computer and use it in GitHub Desktop.
Save cssoul/5479661 to your computer and use it in GitHub Desktop.
去掉数组中的重复元素
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