javascript - Filtering out values of a bidimensional array -


i have bidimensional array looks this:

[[10, 20, 30, s1] [10, 20, 30, s1] [10, 20, 30, s1] [50, 70, 80, g1] [50, 70, 80, g1] [50, 70, 80, g1]] 

i want filter out every "non-first" occurence of 4th value of each sub-array, this:

[[10, 20, 30, s1] [10, 20, 30] [10, 20, 30] [50, 70, 80, g1] [50, 70, 80] [50, 70, 80]] 

how possible? in advance

you can use object keep track of found values, , remove last item subarrays when found before:

var items = {}; (var = 0; < arr.length; i++) {   var id = arr[i][arr[i].length - 1];   if (items.hasownproperty(id)) {     arr[i].pop();   } else {     items[id] = 1;   } } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -