How to get the index value of the largest three numbers in an array

var arr = [6,8,2,4,9,0];

for example, what is the index value of the largest three numbers in the array above? is there a good way

Mar.24,2021

this article sums up well you can take a look at


I wonder if you consider duplicate data. What if you do? For a simple implementation, assume that there is no repetition in the array, make a copy, sort it, find the three largest values, and then compare it with the original array. There is another way: Math.max finds the maximum, finds his index assumption I, and assigns the value of index I to be less than the minimum. Loop this operation three times.

Menu