03-Aug-2022
.
Admin
Hello Dev,
Today, how to get the max elements of an array in node js is our main topic. if you have a question about get the max elements of an array in node js then I will give a simple example with the solution. you can understand the concept of find max elements of an array in node.js. it's a simple example of find the max elements of an array in node.js. you will do the following things for how to get the max value in the array.
This example is how to get max elements of an array in node js. I will give you examples of get the max value in the array list. In this example get 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
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