Skip to main content

[JS] apply

caution

This is not original content, but just a note from articles I read.

Intro

The apply() method calls the specified function with a given this value, and arguments provided as an array.

const numbers = [5, 6, 2, 3, 7];

const max = Math.max.apply(null, numbers);

console.log(max);
// Expected output: 7

const min = Math.min.apply(null, numbers);

console.log(min);
// Expected output: 2

Reference