How to find the largest number in an array in JavaScript?

To find the largest number in an array in JavaScript, do this: Math.max(...array).

Use the spread operator ... to pass all array items into the Math.max function:

const array = [ 4, 5, 20, 1, 101, 2 ];
const largestNumber = Math.max(...array);

console.log(largestNumber); // 101