javascript - Removing an array of indexes from an given array -
so having bit of difficulty trying think of best way of doing in javascript. want remove array of unsorted indexes array x number of elements. example
var index = [ 0, 7, 10, 2, 5, 11] array = [{field0: 0}, {field1: 1}, {field2: 2}, ... {field5: 5}, {field6: 6}...]
so tried using nested loop splice, when splice, array loses indexing , screws up.
the end result should come out array = [{field1: 1}, {field3: 3}, {field4: 4}, .... {field6: 6} ...]
any appreciated.
the solution problem one-liner:
array = [00,11,22,33,44,55,66,77]; indexes = [1,7,5,3]; array = array.filter(function(_,i) { return indexes.indexof(i) < 0 }); document.write('<pre>'+json.stringify(array,0,3));
Comments
Post a Comment