Answers for "javascript highest value of array"

30

max value in array javascript

// For large data, it's better to use reduce. Supose arr has a large data in this case:
const arr = [1, 5, 3, 5, 2];
const max = arr.reduce((a, b) => { return Math.max(a, b) });

// For arrays with relatively few elements you can use apply: 
const max = Math.max.apply(null, arr);

// or spread operator:
const max = Math.max(...arr);
Posted by: Guest on November-27-2020
0

Return the highest number in Arrays in JavaScript

function largestOfFour(arr) {
  return arr.map(Function.apply.bind(Math.max, null));
}
Posted by: Guest on December-08-2021

Code answers related to "javascript highest value of array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language