0

In the following:

let items = [
  {
     itemName: "Effective Programming Habits",
     type: "book",
     price: 13.99
  },
  { 
     itemName: "Creation 3005",
     type: "computer",
     price: 299.99
  },
  {
     itemName: "Finding Your Center",
     type: "book",
     price: 15.00
  }
]


function myFunction(max, {price}) {
   if (price > max) {
     return price
   }
   return max
 }

why does {price} return the price value for each object? why not item['price'] or item.price? Whre do you find the answer in the documentation? What do you look for?

mzedeler
  • 4,177
  • 4
  • 28
  • 41
DCR
  • 14,737
  • 12
  • 52
  • 115

1 Answers1

-1

Whenever you need to check js documentation, MDN is in my opinion the best answer, check the Array section for exmample https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference./Global_Objects/Array You can try something like this:

const highestPrice = (myArray) => {
    let max = 0; //variable to return
    for(let i = 0; i < myArray.length; i++){
        if(myArray[i].price > max){ //check current element
            max = myArray[i].price;
        }
    }
    return max;
}
DiegoP
  • 35
  • 1
  • 8