获取与JavaScript中的最高值数组键 [英] Get the array key with the highest value in javascript
本文介绍了获取与JavaScript中的最高值数组键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像
arr[1] = 234;
arr[2] = 345;
...
arr[40] = 126;
我怎样才能获得最高价值的元素的索引,而不重申阵列?
How can I get the index of the element with the highest value without reiterating the array?
推荐答案
您可以申请Math.max和传递数组作为参数 -
You can apply Math.max and pass the array as its arguments-
arr.indexOf(Math.max.apply(window,arr))
但现在Math.max是做迭代,就像那种会做。
But now Math.max is doing the iterating, just as sort would do.
有人有看每个项目在排序的数组...
Somebody has to look at each item in an unsorted array...
这篇关于获取与JavaScript中的最高值数组键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文