高效数组去重
- Array.prototype.unique = function()
- {
- var n = {}, r = [], len = this.length, val, type;
- for (var i = 0; i < this.length; i++) {
- val = this[i];
- type = typeof val;
- if (!n[val]) {
- n[val] = [type];
- r.push(val);
- } else if (n[val].indexOf(type) < 0) {
- n[val].push(type);
- r.push(val);
- }
- }
- return r;
- }