flatten - extract children + parent details using lodash -
i have following json structure , want extract information particular team given id including division belongs to.
{ "teams":[ { "divisionname":"5th grade - green", "divisionteams":[ { "id":3222, "name":"columbia ravens 5th", "coach":"john miller" }, { "id":3220, "name":"hc elite omalley 5th", "coach":"eddie omalley" } ] }, { "divisionname":"5th grade - white", "divisionteams":[ { "id":3225, "name":"cbsa hoyas 5th grade", "coach":"terrance taylor" }, { "id":3276, "name":"hc elite 4th tookes", "coach":"anthony tookes" }, ] }
] }
i tried using following lodash code, came undefined.
var team=_.chain(data.teams) .flatten("divisionteams") .find({"id":3222 }) .value(); console.log(team);
any appreciated.
you can need find() , some(). there's no need flatten arrays.
_.find(teams, function(item) { return _.some(item.divisionteams, { id: 3222 }); });
Comments
Post a Comment