📌  相关文章
📜  通过其属性之一在数组中查找对象 - 无论代码示例

📅  最后修改于: 2022-03-11 14:55:47.809000             🧑  作者: Mango

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

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

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