function findIndicesOf(haystack, needle)
{
var indices = [];
var j = 0;
for (var i = 0; i < haystack.length; ++i) {
if (haystack[i] == needle)
indices[j++] = i;
}
return indices;
}
pass array
to haystack
and Math.max(...array)
to needle
. This will give all max elements of the array, and it is more extensible (for example, you also need to find min values)