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

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -

python - How to create a legend for 3D bar in matplotlib? -