01-Aug-2022
.
Admin
Hi friends,
In this tute, we will discuss how to get min and max elements of an array in node js. I would like to show you get min elements of an array in node js. In this article, we will implement get max elements of an array in node js. it's a simple example of find the min and max elements of an array in node.js. So, let's follow a few step to create an example of find max elements of an array in node js.
This example is how to get min and max elements of an array in node js. I will give you two examples of get the min value from the array list and the max value in the array list. In this example get the min value using the min function and the max value using the max function from the array list.
let's see below a simple example with output:
Install Node JS
This step is not required; however, if you have not created the node js app, then you may go ahead and execute the below command:
mkdir my-app
cd my-app
npm init
Example: 1
index.js
//create array list
var myArray = [1, 5, 6, 2, 3];
// get min value
var minVal = Math.min.apply(null, myArray);
console.log(minVal)
Output:
1
Example: 2
index.js
//create array list
var myArray = [1, 5, 6, 2, 3];
// get max value
var maxVal = Math.max.apply(null, myArray);
console.log(maxVal )
Output:
6
I hope it can help you...
#Node JS