使用Set集合:
Array.prototype.uniq = function () { return Array.from(new Set(this)); }
reduce+includes方法:
Array.prototype.uniq = function () { return this.reduce((prev, cur) => { return prev.includes(cur) ? prev : [...prev, cur]; }, []); }
使用Set集合:
Array.prototype.uniq = function () { return Array.from(new Set(this)); }
reduce+includes方法:
Array.prototype.uniq = function () { return this.reduce((prev, cur) => { return prev.includes(cur) ? prev : [...prev, cur]; }, []); }