高效的数组去重(js)

function uniqueArray(data){
data = data || [];
var a = {};
for (var i=0; i<data.length; i++) {
var v = data[i];


a[v] = 1;

console.log(a)
};

data.length=0;
for (var i in a){
console.log(data.length)
data[data.length] = i;
}
console.log(data)
return data;


}
var arrData = [1,3,5,7,7,8,9,3,7,10,8];
uniqueArray(arrData);

posted @ 2016-04-07 19:18  djdliu  阅读(203)  评论(0编辑  收藏  举报