要通过其中一个属性从对象数组中查找对象的话,我们通常使用for
循环:
let inventory = [ {name: 'Bananas', quantity: 5}, {name: 'Apples', quantity: 10}, {name: 'Grapes', quantity: 2} ]; // Get the object with the name `Apples` inside the array function getApples(arr, value) { for (let index = 0; index < arr.length; index++) { // Check the value of this object property `name` is same as 'Apples' if (arr[index].name === 'Apples') { //=>