使用JavaScript从数组中删除重复的元素 [英] Remove duplicate elements from array using JavaScript

查看:109
本文介绍了使用JavaScript从数组中删除重复的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

uniqueElementArray= Array.filter(function(itm,i,Array){
                return i==Array.indexOf(itm);
                });

数组包含1000个甚至超过1000个元素的集合。我们想从这个数组中获取独特的元素。我们正在使用上面提到的函数,最后我们得到了独特的Elements数组,但它正在创建性能问题。我怎样才能提高性能。它在IE8和IE中花费了太多时间。

Array contains set of 1000 or even more than 1000 elements. We want to get unique elements from this array. We are using function which is mentioned above finally we are getting unique Elements array but it's creating performance issue. How can i increase the performance. It's taking too much time in IE8 and IE9.w

推荐答案

我建议使用 underscore.js

var otherArray = _.uniq(array);

你可以看到它是如何实现的这里

You can see how it's implemented here.

这篇关于使用JavaScript从数组中删除重复的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆