let arr = [1, 4, 6, 1, 2, 8] // 去重 Array.prototype.unRepeat = function () { let obj = {}, res = null // this.forEach( item => { // obj[ item ] = true // }) while( res = this.shift() ) { obj[ res ] = true } Object.keys( obj ).forEach( key => { this.push( key ) }) return this } arr = arr.unRepeat() console.log( arr )