The principle of implementation: the sequential lookups of arrays are very similar, and they are all data-specific pairs.
Don't say much nonsense ~
The code is as follows:
/** Parameter Description: * Array: Incoming array, for example: var arr = [5,7,66,78,99,103,126,203,1]; */ functionfindmin (array) {var_min = array[0];//Suppose the smallest number is array[0] var_indexmin = 0;//assuming the lowest number of subscripts is 0. for(vari=0;i<array.length;i++){ if(Array[i] < _min) {//if the other elements are greater than the values we assume, it proves that the values we assume are not the smallest_min = Array[i];//Reset The value of the _min_indexmin =i; } } return"The smallest number is:" + _min + "; Subscript:" +_indexmin; }; //Call: vararr = [5,7,66,78,99,103,126,203,1]; document.write (Findmin (arr));
can also be corrected, find the largest number of arrays, I will not write, the principle of the same as this ~ ~
Can not understand the place at any time to give me a message ~
The great God, please ignore ~ ^_^
JavaScript finds the smallest/largest number in an array