let fruit = [ {name: '苹果', price: '5元'}, {name: '香蕉', price: '3元'}, {name: '西瓜', price: '4元'}];
const getFruitName = (arr, val) => arr.find(obj => obj.name === val)
console.log(getFruitName(fruit, '苹果'));
console.log(getFruitName(fruit, '香蕉'));
console.log(getFruitName(fruit, '西瓜'));
js数组中查找对象的简单写法
于 2023-05-25 11:28:00 首次发布