javascript - Filter nested array of objects by object property in d3.js -


i have meteorite landings dataset.
nested data in 4 keys, type:

  var databytype = d3.nest()     .key(function(d) {           return d.rectype;     })     .entries(dataset); // original array 

this resulting structure: data

enter image description here

now want create new arrays, filtering nested one: want each filtered array contain objects "mass" property inside defined range.
tried this:

// filter small meteorites var lightweight = databytype.foreach(function(d){       d.values.filter(function (object) {             var mass = object.mass;             return mass <= 100;       });   }); 

but returns undefined.

nesting giving me lot of trouble! do wrong?
thanks in advance

i think you're overwriting lightweight on each pass of foreach. instead try creating lightweight own object, adding keys want in loop:

const lightweight = {};  databytype.foreach(function(d){   lightweight[d.key] = d.values.filter(function (object) {     var mass = object.mass;     return mass <= 100;   }); }); 

working pen (i think?) doing want: https://codepen.io/benjaminwfox/pen/vebjrp?editors=0012


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -