我通过jQuery的each函数获取我的数组列表。
在我上面的例子中,我应该得到...
var spnTxt = '';
var arr = $('#id').find('span').each(function(utval) {
spnTxt = $(this).text();
});
这让我感到
["pet", "dog", "london", "class"]
["pet", "cat", "newyork", "weight"]
["tech", "phone", "spain", "hello2"]
["tech", "phone", "spain", "hello"]
["tech", "phone", "spain", "hello"]
在我上面的例子中,我应该得到...
["pet", "dog", "london", "class"]
["pet", "cat", "newyork", "weight"]
["tech", "phone", "spain", "hello2"]
["tech", "phone", "spain", "hello"]
这是一个独特的问题。我的下面代码不起作用。我不确定它是否正确。
var dup = {};
var arr = $('#id').find('span').each(function(utval) {
spnTxt = $(this).text();
if (dup[spnTxt])
$(this).remove();
else
dup[spnTxt] = true;
});
基本上我想删除重复的数组,如果我的数组中的字符串完全相同。如何实现此目标?