本文介绍了从二维数组在Javascript中删除重复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
什么将是一个很好的算法,以消除类似下面的阵列上易受骗的人......
What would be a nice algorithm to remove dupes on an array like below...
var allwords = [
['3-hidroxitiramina', '3-hidroxitiramina'],
['3-hidroxitiramina', '3-hidroxitiramina'],
['3-in-1 block', 'bloqueo 3 en 1'],
['abacterial', 'abacteriano'],
['abacteriano', 'abacteriano'],
['abciximab', 'abciximab'],
...
只是为了澄清,我想的一个
Just to clarify, I would want one of the
['3-hidroxitiramina', '3-hidroxitiramina'],
要被删除,因此只有一个
To be removed, so there is just one
推荐答案
:误读,读你的澄清后,我会建议:
[edit]: misread, after reading your clarification I'd suggest:
var i = allwords.length-1, prev='';
do {
if (allwords[i].join('/') === prev) {
allwords.splice(i,1);
}
prev = allwords[i].join('/');
} while (i-- && i>-1);
(扭转循环是一个优化步骤)
(reversing the loop is a optimization step)
这篇关于从二维数组在Javascript中删除重复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!