- 论坛徽章:
- 0
|
javascript 数组去除重复值
再网上看到这个是比较好的
Java代码- Array.prototype.unique = function(){
- var newArray = [],
- temp = {};
- for(var i = 0; i < this.length; i++){
- temp[typeof(this[i])+this[i]] = this[i];
- }
- for(var j in temp){
- newArray.push(temp[j]);
- }
- return newArray;
- };
- Array.prototype.unique = function(){
- var newArray = [],
- temp = {};
- for(var i = 0; i < this.length; i++){
- temp[typeof(this[i])+this[i]] = this[i];
- }
- for(var j in temp){
- newArray.push(temp[j]);
- }
- return newArray;
- };
复制代码 http://www.cssbox.net/javascript-array-unique.html
|
|