标签:== 创建 ++ 没有 uniq type for code log
var arr = [1,23,1,1,1,3,23,5,6,7,9,9,8,5];
3 Array.prototype.reArr = function(){
4 var newArr = [];
5 for(var i = 0; i < this.length; i++){
6 if(newArr.indexOf(this[i])== -1){
7 newArr.push(this[i]);
8 }
9 }
10 return newArr;
11 }
12 var arr2 = arr.reArr();
13 console.log(arr); //[ 1, 23, 1, 1, 1, 3, 23, 5, 6, 7, 9, 9, 8, 5 ]
14 console.log(arr2);//[ 1, 23, 3, 5, 6, 7, 9, 8 ]
function unique3(arr){
var res = [];
var obj = {};
for(var i=0; i<arr.length; i++){
if( !obj[arr[i]] ){
obj[arr[i]] = 1;
res.push(arr[i]);
}
}
return res;
}
console.log(‘------------方法三---------------‘);
console.log(unique3([1,1,2,3,5,3,1,5,6,7,4]));
标签:== 创建 ++ 没有 uniq type for code log
原文地址:https://www.cnblogs.com/web-record/p/9141373.html