1
如何過濾數組是否在另一個數組內?過濾內部數組javascript
我該如何循環?
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」))'使用'some'以查看是否之一「辦公室」陣列內的對象符合您的要求。 – user3297291