Q.MEO
0
Q:

how to return the max and min of an array in javascript

const array1 = [1, 3, 2];
console.log(Math.max(...array1));
2
let numbers = [4, 13, 27, 0, -5]; // Get max value of an array in Javascript

Math.max.apply(null, numbers); // returns 27
2
function minMax(arr) {
  return [Math.min(...arr), Math.max(...arr)];
}
1
var numbers = [1, 2, 3, 4];
Math.max(...numbers) // 4
Math.min(...numbers) // 1
0

New to Communities?

Join the community