Answers for "get highest value in array of objects js"

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

how to get max value from array of objects in javascript

// how to get max value from array of objects in javascript
let arr = [
{
'id':2,
'name':'chetan',
},
{
'id':5,
'name':'akash',
},
{
'id':1,
'name':'ujesh',
},
{
'id':4,
'name':'jeny',
},
{
'id':3,
'name':'mayur',
}];
const result = (arr) => Math.max(...arr.map(val => val.id));
console.log(result(arr)); // 5
Posted by: Guest on January-23-2022

Code answers related to "get highest value in array of objects js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language