I have an array of event objects called events. Each event has markets, an array containing market objects.
var events = [
{
id: 'a',
markets: [{
outcomes: [{
test: 'yo'
}]
}]
},
{
id: 'b',
markets: [{
outcomes: [{
untest: 'yo'
}]
}]
},
{
id: 'c',
markets: [{
outcomes: [{
notest: 'yo'
}]
}]
},
{
id: 'd',
markets: [{
outcomes: [{
test: 'yo'
}]
}]
}
];
var matches = events.filter(function (event) {
return event.markets.filter(function (market) {
return market.outcomes.filter(function (outcome) {
return outcome.hasOwnProperty('test');
}).length;
}).length;
});
matches.forEach(function (match) {
document.writeln(match.id);
});
Here's how I would do it, without depending on a library:
var matches = events.filter(function (event) {
return event.markets.filter(function (market) {
return market.outcomes.filter(function (outcome) {
return outcome.hasOwnProperty('test');
}).length;
}).length;
});