[英]Remove Same values array Jquery
How do I remove the repeated array which has the same values as the first array. 如何删除具有与第一个数组相同值的重复数组。 Below is the array I have. 下面是我拥有的数组。 Can anyone help me out on this. 谁能帮我这个忙。
I need to remove the repeated array which is second one and show only the 1st array. 我需要删除第二个重复数组,并仅显示第一个数组。
JS: JS:
arr = [ [10,20] , [10,20] ]
jQuery的唯一性仅适用于DOM元素,我认为您正在寻找的是下划线库中的uniq,该库可在http://underscorejs.org/#uniq中找到
You can try 你可以试试
function arraysEqual(a1,a2) {
return JSON.stringify(a1)==JSON.stringify(a2);
}
Try this:- 尝试这个:-
var arr = [ [10,20] , [30,20],[10,40],[10,20],[30,20] ],newArr=[];
$.each(arr, function(index,item){
if(searchForItem(newArr,item)<0){
newArr.push(item);
}
})
console.log(newArr);
function searchForItem(array, item){
var i, j, current;
for(i = 0; i < array.length; ++i){
if(item.length === array[i].length){
current = array[i];
for(j = 0; j < item.length && item[j] === current[j]; ++j);
if(j === item.length)
return i;
}
}
return -1;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.