There are two things, especially useful, a call called "apply", this is two methods, very powerful.
The maximum number, of course, the minimum number is the same.
var arr=[1,2,3,4,5,6,10,7,9,11,20,19];
Alert (Math.min.apply (Null,arr));//Gets the minimum value in the array
Alert (Math.max.apply (Null,arr));//Gets the maximum value in the array
Ask for the maximum subscript
var index_ =arr.indexof (Math.max.apply (Math, arr)); To get the maximum value of the subscript similarly, the minimum subscript is the min.
So what's the principle?
Apply method: Syntax: Apply ([Thisobj[,argarray]]) Definition: Apply one method of an object, replace the current object with another object. Description: If Argarray is not a valid array or is not a arguments object, it will result in a TypeError. If none of the Argarray and Thisobj parameters are provided, then the Global object is used as a thisobj and cannot be passed any parameters.
The parameters of the apply reference must be in the form of an array, and the function and call are the same. Instead of replacing the current object with other objects, I can only understand that the current object has no function for the other object.
Reference: Portal
Maximum element and subscript of an array