Categories
JavaScript Answers

How to find the largest number contained in a JavaScript array?

Spread the love

To find the largest number contained in a JavaScript array, we use the Math.max method and the spread operator.

For instance, we write

const arr = [1, 2, 3];
const max = Math.max(...arr);

to call Math.max with the entries in the arr array as arguments.

We use the spread operator to spread the entries as arguments.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published.