How do I filter if an array is inside another array?
How should I loop this?
var jobs = [
{
'id': '1',
'departments': [{'name': 'Finance'}],
'offices': [{'name': 'US'}, {'name': 'Brazil'}]
},
{
'id': '1',
'departments': [{'name': 'Finance'}],
'offices': [{'name': 'Paris'}, {'name': 'China'}]
}
];
var results = jobs.filter(function(o)) {
return o.offices[0].name == 'US';
} // get office US;
jobs.filter(j => j.offices.some(o => o.name === "US"))Usesometo see if one of the objects inside theofficesarray matches your requirement.