How to find the maximum number of an array in javascript
In this post we will give you information about How to find the maximum number of an array in javascript. Hear we will give you detail about How to find the maximum number of an array in javascriptAnd how to use it also give you demo for it if it is necessary.
To find the Maximum number in the array of elements we can use Math.max( ) method in JavaScript.
Math.max( ) method accepts the numbers as an argument and returns, the maximum number.
syntax: Math.max(number1,number2,..)
let arr = [11,2,3,565,53,2];console.log(Math.max(...arr)) // 565
In the above code we used (…)spread operator to spread the array of numbers into individual numbers.
We can write our function by using above logic.
function findMax(arr) { if (!arr) { return; } return Math.max(...arr);}console.log(findMax([4,32,64,39,26])) // 64console.log(findMax([10,-10])) // 10console.log(findMax()) // undefined
Hope this code and post will helped you for implement How to find the maximum number of an array in javascript. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs