Answers for "how to get max value of given array of objects in javascript"

7

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
1

js get max value in an array

const myArray = [1, 14, 32, 7];

const maxValue = Math.max(...myArray);

console.log(maxValue); // 32
Posted by: Guest on February-01-2022

Code answers related to "how to get max value of given array of objects in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language