题解 | #数组去重#
数组去重
http://www.nowcoder.com/practice/0b5ae9c4a8c546f79e2547c0179bfdc2
includes方法可以感知 undefined、null、NaN,对于对象检查的是地址,所以不同对象不会导致includes为true
Array.prototype.uniq = function () {
let temp = []
this.forEach(e => {
if (!temp.includes(e)) temp.push(e)
})
return temp
}