How to get the index of the highest value of an array?

Hi all!

Im super new at javascript. I created an array and I want to know which index hold the highest number.
I got this code:
Code:
var a = [0, 21, 22, 7];
var indexOfMaxValue = a.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);

console.log("indexOfMaxValue = " + indexOfMaxValue);

When I try it on a javascript sandbox, it does what I want but If I try it on the RPGMAKER MV console, it sayts unexpected token "=>".
Im guessing I cant just run that code on the console? or maybe because im in version 1.51 that I cant run that specific code?

Any how, any help to achieve what I need would be appretiated.

Thanks!
You can try this 😀
Code:
var indexOfMaxValue = a.indexOf(Math.max.apply(null, a));
Ha, so simple. Thanks!!!
If I try it on the RPGMAKER MV console, it sayts unexpected token "=>".
That token is an arrow function, which was added in the 2015 specification of Javascript. MV 1.5 and earlier doesn't support this syntax, to use 2015+ features, you'd have to upgrade MV to 1.6

Another option is the spread operator (2015+):

Code:
a.indexOf(Math.max(...a))

Original thread: https://forums.rpgmakerweb.com/threads/how-to-get-the-index-of-the-highest-value-of-an-array.108496/