How to get the index of the max value in an array in JavaScript

1 Answer

0 votes
const arr = [4, 6, 9, 2, 0, 8, 7];

const index = arr.indexOf(Math.max(...arr));

console.log(index);




/*
run:
  
2
  
*/

 



answered Jul 8, 2022 by avibootz

Related questions

...