i have array contains number of subarrays
, each containing 2 values.
i.e: interestarray[[1, 5], [3, 8] ... ]
how remove subarray
containing values [3, 8]?
my code is:
$('td', container).click(function(){ if(!$(this).hasclass('purchased') && !$(this).hasclass('manu')) { var manuid = $(this).parent().children('td:first-child').data('manu-id'); var typeid = $(this).data('type-id'); if($(this).hasclass('interest')) { $(this).removeclass('interest'); $(this).parent().children('td.manu').removeclass('interest'); var index = interestarray.indexof([manuid, typeid]); interestarray.splice(index, 1); } else { $(this).addclass('interest'); $(this).parent().children('td.manu').addclass('interest'); interestarray.push([manuid, typeid]); } //updatesurvey(interestsarray); console.log(interestarray) } })
the below section not work, , removes first subarray
.
var index = interestarray.indexof([manuid, typeid]); interestarray.splice(index, 1);
here's generic approach requirements:
var arr = [[1,2],[3,4],[5,6]]; var remove = [3,4]; (var i=0; i<arr.length; i++) { if (arr[i][0] == remove[0] && arr[i][1] == remove[1]) { arr.splice(i, 1); break; } } console.log(arr); //=> [[1,2],[5,6]]
Comments
Post a Comment