<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
Array.prototype.delRepeat = function(){
var arrRepeat = [];
var obj = {};
for (var i = 0;i < this.length;i++){
if (obj[this[i]]){
if (obj[this[i]] == 1){
arrRepeat.push(this[i]);
obj[this[i]]++;
delete(this[i])
}
}else{
obj[this[i]] = 1;
}
}
return arrRepeat;
}
var a = [1,2,2,3,4,5,5];
alert(a.delRepeat());
</script>
</head>
<body>
</body>
</html>
网友评论