ES6 Find the maximum number of an array of objects

前端 未结 7 1287
栀梦
栀梦 2021-01-14 17:27

I have the following data

shots = [
    {id: 1, amount: 2},
    {id: 2, amount: 4}
]

Now I\'m trying to get the object which

相关标签:
7条回答
  • 2021-01-14 18:04

    You can use this code. It will simply return the highest amount.

    Math.max.apply(Math,shots.map((shot)=>{return shot.amount;}));
    
    0 讨论(0)
提交回复
热议问题