📌  相关文章
📜  从数组中返回第一个匹配的对象 - 无论代码示例

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

代码示例1
function priceLookup(items, name) {

  for (let i = 0; i < items.length; i++) {
    if (name === items[i].itemName) {
      // the return will break the loop and exit the function
      return items[i].price;
    }
  }
  // if loop completes no matches were found
  return "No item found with that name"
}