js-数组去重

function unique(arr) {
debugger;
var result = [], hash = {};
for (var i = 0, elem; (elem = arr[i]) != null; i++) {
if (!hash[elem]) {
result.push(elem);
hash[elem] = true;
}
}
return result;
}

var aTest=[1,2,3,3,3,4,5,9];
console.log(unique(aTest))
posted @ 2015-02-13 14:40  zhouyan_jsj  Views(104)  Comments(0Edit  收藏  举报