I currently have data that looks like this:
[{
"id": 1,
"name": "Canada",
"checked": true,
"vacationSpots": [{
"id": 1,
"name": "Toronto",
"checked":false,
"activities": [{
"id": 1,
"checked": false,
"name": "Niagara Falls"
}]
}, {
"id": 2,
"name": "France",
"checked":true,
"activities": [{
"id": 2,
"checked":true,
"name": "Eiffel tower"
}]
}]
}, {
"id": 2,
"name": "US",
"checked": true,
"vacationSpots": [{
"id": 3,
"name": "California",
"checked": true,
"activities": [{
"id": 3,
"name": "Surfing",
"checked":false
}]
}]
}]
I'm gathering the activities id's from activities which have checked set to true.
so the result looks something like this:
2
While I can get this, I have to go through 3 levels before I can access activities
for (i = 0; i < country.length; i++){
country = allAreas[i];
....
for (j = 0; j < country.vacationSpots.length; j++){
....
for (k = 0; k < vacationSpots.activities.length; k++){
(Search through country, then vacationSpots, then activities. Is there a way to filter this without traversing through each level? Is there a way to do this with Lodash?