
删除js数组中的重复元素
var array = [1,'1',1,'1',true,'true',2,3,2];
所需的结果是: [1,'1',true,'true',2,3];该顺序不是必需的,但是时间复杂度尽可能低,最好为O(n). 在给出答案之前,请务必先对其进行测试,否则Internet上的示例将无法正常工作.
||最喜欢的||
2个答案
按喜欢排序

这是您想要的结果,给出答案,您可以尝试一下
var array = [1,'1',1,'1',true,'true',2,3,2];
Array.prototype.distinct = function(){
var newArr = [],obj =(};
for(var i = 0,len = this.length; i if(!obj [typeof(this [i])+ this [i]]){ newArr.push(this [i]); obj [typeof(this [i])+ this [i]] ='new'; } } 返回newArr; }; 警报(array.distinct()); || function districtArray(数组){ var result = new Array(); for(数组中的var i){ if(result.indexOf(array [i])== -1){ result.push(数组[i]); } } 返回结果; }; | 如果要添加问题js array去重复,请编辑问题;解决问题后,请采用答案. 在CSDN问答中,严格禁止抄袭和复制答案以达到声望点或其他目的的行为. 一旦发现js array去重复,将立即予以阻止. 现在该展示真正的技术了!


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/tongxinshuyu/article-158944-1.html
何为发财
斯文是解决不了问题的