我有以下数组
const accounts =[{'accounts':{id:1,name: 'Jill','occupation': 'Welder'}, {id:2,name: 'John','occupation': 'Driver'}, {id:3,name: 'Steve','occupation': 'Accountants'}},
{'accounts':{id:1,name: 'James','occupation': 'Welder'},{id:1,name: 'Steve','occupation': 'Security'},{id:1,name: 'Sarah','occupation': 'Waiter'}},
{'accounts':{id:1,name: 'George','occupation': 'Developer'},{id:1,name: 'Andrew','occupation': 'Security'},{id:1,name: 'Frank','occupation': 'Welder'}}];
我希望能够选择像焊工或司机等......
我试过用这个
const welders= accounts.filter(x => x.accounts.every(ls1=> ls1.occupation ==='Welder'));
但它返回一个空数组。
有人可以建议实现它的最佳方法吗
const welders= accounts.map(x => x.accounts.filter(ls1=> ls1.occupation ==='Welder' || ls1.occupation ==='Driver'));
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句