Answers for "how to check the maximum of a value in an object"

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
0

object get property with max value javascript

var obj = {a: 1, b: 2, undefined: 1};

Object.keys(obj).reduce((a, b) => (obj[a] > obj[b]) ? a : b);
Posted by: Guest on January-20-2021

Code answers related to "how to check the maximum of a value in an object"

Code answers related to "Javascript"

Browse Popular Code Answers by Language