Today we share a method that is for arrays. In our daily work, we may have a headache when we encounter an array of problems. In particular, let's look for the maximum minimum value from a grotesque array. Although we have described a method for finding the maximum minimum of an array, the method is only used for numeric values in arrays.
Next, the method that I'm going to introduce applies to any array, and this method picks out the values in the array, which is larger than the size.
HTML code:
Copy Code code as follows:
<div id= "box" >
<b>[' 1200px ', #, ' abc ', 4, 90, [], ' 12.56 ', function () {}, ' xyz ' -30, True, number (' abc ')]</b>
<p> maximum and minimum values are: <input id= "Inpu" type= "button" value= "Display"/></p>
</div>
HTML preview:
JavaScript code:
Copy Code code as follows:
var arr = [' 1200px ', +, ' abc ', 4, 90, [], ' 12.56 ', function () {}, ' xyz ' -30, True, number (' abc ')];
/*
Find the maximum and minimum values: 1200, 4
*/
Window.onload = function () {
var arr = [' 1200px ', +, ' abc ', 4, 90, [], ' 12.56 ', function () {}, ' xyz ' -30, True, number (' abc ')];
/*
Getminmax method of obtaining maximum minimum value
Arr array gets the maximum minimum value
Num number can be passed to big or small
Returns the number argument if big returns the maximum value, small returns the minimum value
*/
function Getminmax (arr,num) {
var big = parseint (Arr[0]),
small = parseint (Arr[0]),
i = 0,
Al = Arr.length;
for (i = 0; i < al; i++) {
if (parseint (Arr[i]) > Big) {
Big = parseint (Arr[i])
else if (parseint (Arr[i]) < small) {
small = parseint (Arr[i]);
}
}
if (num== "big") return to big;
else if (num== "small") return small;
}
Click on the display, the maximum value of 12 or the minimum value of 4
document.getElementById ("Inpu"). onclick = function () {
This.parentNode.innerHTML = "2. The maximum and minimum values are:" + Getminmax (arr, "big") + "," + Getminmax (arr, "small");
}
}
Preview Effect:
The above is the smallest method of array that I share. Hope to help you. What advice can we talk about at any time, huh? ~