Array.prototype.unique = function() { var res = [], hash = {}; for(var i=0, elem; (elem = this[i]) != null; i++) { if (!hash[elem]) { res.push(elem); hash[elem] = true; } } return res;};
数组去除重复,用法:
var a = [1,2,3,3,3,3,4];alert(a.unique());