How to Get Min Elements of an Array in Node JS?

02-Aug-2022

.

Admin

How to Get Min Elements of an Array in Node JS?

Hi friends,

I am going to show you example of how to get the min elements of an array in node js. I would like to show you get min elements of an array in node js. let’s discuss about find min elements of an array in node.js. it's simple example of how to get min value in the array.

This example is how to get min elements of an array in node js. I will give you examples of get the min value from the array list. In this example get the min value using the min 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

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

I hope it can help you...

#Node JS