js实现数组去重
<script>
Array.prototype.myUnique = function(){
var obj = {};
for(var i = 0; i < this.length; i++){
var cur = this[i];
if(obj[cur] == cur){
this[i] = this[this.length-1];
this.length--;
i--;
continue;
}
obj[cur] = cur;
}
obj = null;
return this;
}
var arr = [1,2,6,5,7,5,6];
// 链式写法:执行数组的一个方法紧接着执行另外一个方法
arr.myUnique().sort(function(a,b){return a-b;});
console.log(arr);
</script>