Math.max和Math.max.apply

Math.max.apply用来求取一个数组中最大值得下标

var  a = [12,34,23,23,34,45]
var  b = a.indexOf(Math.max.apply(Math, a))
console.log(b) // 5

如果一个数组中最大值有两个值,则返回第一个最大值的下标

var  a = [12,34,23,23,34]
var  b = a.indexOf(Math.max.apply(Math, a))
console.log(b) // 1

  

猜你喜欢

转载自www.cnblogs.com/fanlina/p/8931834.html
今日推荐