javascript - Alter array using $.grep() -
currently, use $.grep filter , remove elements array pass. believe $.grep intended used filtering only, since it's iterating on entire array, figured might alter array inside well.
do have other approaches can suggest? had thought $.map, afaik should used translating elements, , not removing them.
is separate $.each
alternative?
the relevant part of code:
$.each(filter, function (k, v) { if (v.codekeys) { $.each(v.codekeys, function (i, codekey) { rows = $.grep(rows, function (v2, i2) { if ($.isarray(v2[v.dbcolumn]) && $.inarray(codekey, v2[v.dbcolumn]) === -1) { var index = $.inarray(codekey ,v2[v.dbcolumn]); if (v2[v.dbcolumn][index]) v2[v.dbcolumn].remove(index); return true; } else { return v2[v.dbcolumn] !== codekey; } }); }); } });
$.map can used remove items array, make return null:
var items = [1, 2, 3, 4] $.map(items, function(i) { if (i == 2) return null; return i; }) result: [1, 3, 4]
from the documentation:
the function can return: * translated value, mapped resulting array * null or undefined, remove item
Comments
Post a Comment