标签:
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 arr = new Array(1, 3, 4, 5, 3); arr = arr.unique(); alert(arr.join(",")) //输出1,3,4,5
标签:
原文地址:http://www.cnblogs.com/caoyc/p/5715152.html