Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the Min and Max methods of JavaScript

Shulou Source: shulou.com Published: 2022-06-01 10:33:05 09月19日 Update

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.

Tags: Content method function instance array article knowledge article lowest highest value most that is more minimum maximum step knowledge point industry information Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker Shulou Technology Xiaomi Apple Huawei