Array.prototype.prevRepeat = function(){
var newArr = new Array();
var Obj = new Object();
for(var i = 0;i<this.length;i++){
if(!Obj[this[i]]){
Obj[this[i]] = 1;
newArr.push(this[i]);
}
}
return newArr;
}
var arr = [1,2,1,1,5]
console.log(arr.prevRepeat())
时间: 2024-10-24 14:59:09