Array.prototype.del = function(){ var a = {}, c = [], l = this.length; for (var i = 0; i < l; i++) { var b = this[i]; var d = (typeof b) + b; if (a[d] === undefined) { c.push(b); a[d] = 1; } } return c; }
本文介绍了一种使用JavaScript实现的简单数组去重方法。通过遍历数组并利用对象存储已存在的元素来过滤重复项,最终返回一个不含重复元素的新数组。
Array.prototype.del = function(){ var a = {}, c = [], l = this.length; for (var i = 0; i < l; i++) { var b = this[i]; var d = (typeof b) + b; if (a[d] === undefined) { c.push(b); a[d] = 1; } } return c; }
转载于:https://www.cnblogs.com/magicyk/p/4443488.html

被折叠的 条评论
为什么被折叠?
