📌  相关文章
📜  javascript 按属性值在数组中查找对象 - Javascript 代码示例

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

代码示例6
const fruits = ['apple', 'banana', 'grapes', 'mango', 'orange'];

const filterItems = (needle, heystack) => {
  let query = needle.toLowerCase();
  return heystack.filter(item => item.toLowerCase().indexOf(query) >= 0);
}

console.log(filterItems('ap', fruits)); // ['apple', 'grapes']
console.log(filterItems('ang', fruits)); // ['mango', 'orange']