How to use the Min and Max methods of JavaScript
Most people do not understand the knowledge points of this article "how to use JavaScript's Min and Max methods", so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "JavaScript Min and Max method how to use" article.
This function iterates through the array, comparing each value with the highest value found:
Instance (find Max)
Function myArrayMax (arr) {
Var len = arr.length
Var max =-Infinity
While (len--) {
If (arr [len] > max) {
Max = arr [len]
}
}
Return max
}
This function iterates through the array, comparing each value with the lowest value found:
Instance (find Min)
Function myArrayMin (arr) {
Var len = arr.length
Var min = Infinity
While (len--) {
If (arr [len] < min) {
Min = arr [len]
}
}
Return min
}
The above is about the content of this article on "how to use the Min and Max methods of JavaScript". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.