I have a query object that looks like this
{
"regions": [],
"countries": [],
"channels": [],
"partners": [],
"branches": [],
"agents": []
}
After populating the arrays in the object it looks like this.
{
"regions": [{
"key": "101",
"value": "Middle East(XX)"
}],
"countries": [],
"channels": [],
"partners": [{
"key": "201",
"value": "Partner A"
}, {
"key": "202",
"value": "Partner B"
}],
"branches": [{
"key": "401",
"value": "Bangalore"
}, {
"key": "402",
"value": "Chennai"
}],
"agents": [{
"key": "501",
"value": "IBM - Metlife"
}]
}
I'm trying to loop through each of these arrays and determine if I should show the filter component. If any of the arrays in the object holds value, I should be showing the filter component
The code:
case false:
let itemsInQuery = 0;
Object.keys(query).forEach((item) => {
itemsInQuery = query[item].length ? itemsInQuery++ : itemsInQuery;
})
itemsInQuery ? this.setState({showBubbles: true, query}) : this.setState({showBubbles: false, query})
break;
I'm not sure what is wrong here, but itemsInQuery is always zero. Also, is there a better way to do this?
Thank you in advance!
itemsInQuery += query[item].length ? 1:0