I have an array structured like this:
[
{"id":"one","name":"school", "selected": false, "children":[
{"id":"1","name":"school", "selected": false},
{"id":"2","name":"student", "selected": true},
{"id":"3","name":"teacher", "selected": false}
]},
{"name":"two","name":"school", "selected": false, "children":[
{"id":"1","name":"school", "selected": true},
{"id":"3","name":"teacher", "selected": false}
]},
{"name":"three","name":"school", "selected": true, "children":[
{"id":"1","name":"school", "selected": false},
{"id":"2","name":"student", "selected": false}
]}
]
I am looking to filter this array in order to extract only the name of objects where the select field is set to true.
The desired output should be an array containing the names of these selected objects:
[student, school, school]
I attempted to achieve this using lodash:
_.filter(array, {selected: true}).map(function (division) {
return array.name;
});
However, this method seems to only return the root objects and not those inside the children property.