DEV Community

Imran Shaik
Imran Shaik

Posted on

Different Ways to find maximum number in javascript

There are several ways to find the maximum number in javascript. they are as follows:

  1. Using Max.math() with spread operator :

let arr = [89, 3, 2, 66, 3, 64, 100, 35]
let max = Math.max(...arr)
console.log(max);

  1. Using reduce() reduce method can be used to accumulate the max value by comparing each element. let arr = [89, 3, 2, 66, 3, 64, 100, 35] let max = arr.reduce((acc, curr)=>(curr>acc?: curr: acc), -Infinity) console.log(max) @here - Infinity is used to ensure that the first comparision always return the first element
  2. using a For Loop: a ``

Top comments (0)

DevCycle image

Fast, Flexible Releases with OpenFeature Built-in

Ship faster on the first feature management platform with OpenFeature built-in to all of our open source SDKs.

Start shipping

👋 Kindness is contagious

Explore this insightful piece, celebrated by the caring DEV Community. Programmers from all walks of life are invited to contribute and expand our shared wisdom.

A simple "thank you" can make someone’s day—leave your kudos in the comments below!

On DEV, spreading knowledge paves the way and fortifies our camaraderie. Found this helpful? A brief note of appreciation to the author truly matters.

Let’s Go!