Having a bit of a nightmare trying to solve this JSON problem. I need to store the number of offers as a tally, but it needs to only be a number whereby the offers have an activated status. In the example below (simplified for illustration) the result should be 2 (as only only of them is false for the 'activated' key). I've tried to target it with this:
var count = Object.keys(object.allOffers[0].offers[0].activated.hasOwnProperty('true')).length;
^^^ but it returns 0. Furthermore it only selects the first offer and I need a method that will target all of the offers that sit inside allOffers. Any ideas? Sample code below.
object {
"allOffers": [
{
"offers": [
{
"offerId": 15661,
"activated": true,
"viewed": false
},
{
"offerId": 15641,
"activated": false,
"viewed": false
},
{
"offerId": 16461,
"activated": true,
"viewed": true
}
]
}
]
}