So I'm trying to get which item has the largest number in 'size' inside the 'items' array. And print out which item as in ('item1','item2', 'item3')
let items = [
{
item: 'item1',
size: 545
},
{
item: 'item2',
size: 89
},
{
item: 'item3',
size: 789
}
]
So I tried with
let sizeMax = Math.max.apply(Math, items.map((o) => {
return o.size;
}))
console.log(sizeMax)
but its not the ES6 way and i cant figure out how i can print the 'item' that has the largest size number out the names I've been trying with:
items.forEach((item) => {
function arrayMax(item) {
return items.size.reduce((h, j) => Math.max(h, j));
}
console.log(items.item)
but I cant quite figure what I'm not getting right