1、返回無重復的新數組(就是原數組刪除重復的元素)
<script type="text/Javascript">
Array.prototype.strip=function(){
if(this.length<2) [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=["123a",85,4,,54,"123a",85,8,8,1,2,5,4,7,8,54,"44"];
alert(arr.strip());
</script>
2、返回被刪元素組成的新數組
<script type="text/Javascript">
Array.prototype.strip=function(){
if(this.length<2) return [];
var arr=[];
var del=[];
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]){
del.push(this.splice(j--,1));
}
}
}
return del;
}
var arr=["123a",85,4,,54,"123a",85,8,8,1,2,5,4,7,8,54,"44"];
alert(arr.strip());
</script>