js 去除数组重复的值
- Array.prototype.unique = function(){
- var a = {};
- var len = this.length;
- for(var i=0; i<len; i++) {
- if(typeof a[this[i]] == "undefined")
- a[this[i]] = 1;
- }
- this.length = 0;
- for(var i in a)
- this[this.length] = i;
- return this;
- }
- var arr = [1,1,1,2,2,2,3,3,4,4];
- arr.unique();
- alert(arr.toString());
把学习一种技术一直坚持下去。