Answers for "find index value of max value in an array"

5

how to find index of max number in js

var a = [0, 21, 22, 7];
var indexOfMaxValue = a.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);

document.write("indexOfMaxValue = " + indexOfMaxValue); // prints "indexOfMaxValue = 2"
Posted by: Guest on August-21-2020
0

js find all max number indexes in array

const arr = [0,1,4,3,4];
const max = Math.max(...arr);
let res = [];
arr.forEach((item, index) => item === max ? res.push(index): null);
console.log(res);
Posted by: Guest on December-30-2021

Code answers related to "find index value of max value in an array"

Code answers related to "Javascript"

Browse Popular Code Answers by Language