I have an array and inside i have a group of objects and how would i loop through them and to make a check for which one of the objects have a status as true?
menuItems: [
{
text1: 'Apple',
status: false,
subItems: []
},
{
text2: 'Orange',
status: false,
subItems: []
},
{
text3: 'Banana',
status: true,
subItems: []
}
]
I tried something like this:-
if(menuItems.forEach(active) === 'false') {
then('do something!!!')
}
let trueItems = menuItems.filter(item => item.status);If you wanted to take it one step further, follow with map.trueItems.map( item => processForTrueItem(item) );forEach? It's possible to do, so butforEachmay not be the best tool for the job.statusoftrue, or could there be several?truestatuses among anysubItems? That would best be handled recursively.