📜  在查找 js 中返回对象列表 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:58.535000             🧑  作者: Mango

代码示例2
const inventory = [
  {name: 'apples', quantity: 2},
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
];

function isCherries(fruit) {
  return fruit.name === 'cherries' && fruit.name === 'bananas';
}

console.log(inventory.find(isCherries));
// { name: 'cherries', quantity: 5 }