var arr = [2,1,2,10,2,3,4,1,85,321,3,4,65,10,24];
function uniq(newarr){
function toObject(arr) {
var obj = { };
for(var i=0 ;i<arr.length ;i++){
obj[ arr[ i ] ]=true;
}
return obj ;
}
function keys(obj){
var arr = [ ] ;
for(var attr in obj){
if(obj.hasOwnProperty(attr)){
arr.push(parseInt(attr));
}
}
return arr;
}
return keys(toObject(newarr));
}
console.log(uniq(arr));
var arr = [2,1,2,10,2,3,4,1,85,321,3,4,65,10,24];
function onRepeat(){
var json={};
var temArr=[];
for(var i=0;i<arr.length;i++){
(function(n){
json[n]=1;
})(i);
}
for(var key in json){
temArr.push(json[name]);
}
return temArr;
}
搞定