javascript get highest value in array of objects code example

Example 1: javascript array find highest value of array of objects by key

Math.max.apply(Math, array.map(function(o) { return o.y; }))

Example 2: 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);

Example 3: find highest number in array javascript

function findHighestNumber(nums) {
	
	let inputs = nums.filter((val, i) => nums.indexOf(val) === i)
	let max = Math.max(...nums);
	let min = Math.min(...nums);
  
   return max + (-min);
}

console.log(difference([1, 7, 18, -1, -2, 9]));

Example 4: how to find max number in array javascript

const array1 = [1, 3, 2];
console.log(Math.max(...array1));

Tags:

Misc Example