Answers for "find max of array of objects key"

3

How to find the max id in an array of objects in JavaScript

const shots = [
  {id: 1, amount: 2},
  {id: 2, amount: 4},
  {id: 3, amount: 52},
  {id: 4, amount: 36},
  {id: 5, amount: 13},
  {id: 6, amount: 33}
];

shots.reduce((acc, shot) => acc = acc > shot.amount ? acc : shot.amount, 0);
Posted by: Guest on March-06-2020
7

find max of array of objects key

Math.max.apply(Math, array.map(function(o) { return o.y; }))
Posted by: Guest on March-05-2020
0

Obtain smallest value from array of objects in Javascript

myArray.sort(function (a, b) {
    return a.Cost - b.Cost
})

var min = myArray[0],
    max = myArray[myArray.length - 1]
Posted by: Guest on May-14-2020

Code answers related to "find max of array of objects key"

Code answers related to "Javascript"

Browse Popular Code Answers by Language