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 arr=["abc",85,"abc",85,8,8,12,12,5,4,7,8]; alert(arr.strip()); |
|