How to find the difference of values in two-dimensional arrays?
arr1 = [[35,70],[433,70],[35,73],[433,73],[35,154],[433,154]] arr2 = [[433,70],[433,154],[433,73],[35,154],[1,2,3]] The result should be:
res = [[35,70],[35,73]] My code is:
var arr1 = [[35,70],[433,70],[35,73],[433,73],[35,154],[433,154]]; var arr2 = [[433,70],[433,154],[433,73],[35,154],[1,2,3]]; var res = []; for (var i = 0; i < arr2.length; i++) { res.push(arr1.splice(arr1.indexOf(arr2[i]), 1)); } console.log(res);//нужно [[35,70],[35,73]] <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
Array.indexOfreturns? - IgorindexOfcalls return-1- Igor