javascript - Filter objects based on a match in another array -
i trying use lodash filter array of objects based on match of id's, have tried:
var team = _.find(this.teams, { 'id': this.newschedule.team}); _.filter(this.yards, function(yard) { return _.find(team.yards, { id: yard.id }); }); yards data:
[ { "id": 1, "name": "test" },{ "id": 2, "name": "test 2" } ] team data:
[ { "id": 1, "name": "team 1", "yards": [{ "id": 1, "name" }] ] i want this.yards show yards based on yard id selected team.
its hard understand mean, yard id match team id?
if sounds need first find team same id grab teams yards. therefore use map function twice:
const result = .yards .map(y => team.find(t => t.id === y.id)) // join right team .map(t => t.yards) // reduce teams yards
Comments
Post a Comment