读书人

js 剔除数组中重复的记录

发布时间: 2012-09-12 09:21:30 作者: rapoo

js 删除数组中重复的记录

        //删除数组中重复的记录Array.prototype.unique = function(){var a = {};for(var i=0; i<this.length; 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;} function delRedata(){var arr = [];arr.push("a");arr.push("b");arr.push("a");arr.push("b");arr.push("e");arr.push("c");arr.push("a");alert(arr.length);var arrays = arr.unique();alert(arrays.length);for(var i=0; i<arrays.length; i++){alert(arrays[i]);}}

读书人网 >JavaScript

热点推荐