Skip to content

Latest commit

 

History

History
20 lines (16 loc) · 592 Bytes

File metadata and controls

20 lines (16 loc) · 592 Bytes

Section 4.1: Finding Object in Array

let Inventory = [
  {name: 'apples', quantity: 2},
  {name: 'bananas', quantity: 0},
  {name: 'cherries', quantity: 5}
];

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

let oneDataOnArray = Inventory.filter((e) => e.name === 'apples')[0];
console.log(oneDataOnArray); // { name: 'apples', quantity: 2 } 

/******** Some how problem in .find() **********/
//console.log(Inventory.find(findCherries)); // { name: 'cherries', quantity: 5 }
//console.log(Inventory.find(findCherries)); // { name: 'cherries', quantity: 5 }