高效的数组去重(js)

时间:2024-11-17 16:03:55

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);