JavaScript Function apply() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Instance method

Definition

apply() runs a function right now, just like call(). The only difference is how you give it the arguments: instead of listing them one by one, you put them all in one array.

It returns whatever the function returns. It is handy when your values are already in an array, for example to find the biggest number in a list with Math.max.

Remember
func.apply(thisArg, argsArray);

thisArg    → what "this" is inside func
argsArray  → an array (or array-like) of arguments
             null or undefined = no arguments
returns    → whatever func returns

apply() runs the function immediately.

Syntax

Call apply() on any function. The first argument is the value for this; the second is an array that holds the arguments.

JavaScript
func.apply(thisArg);
func.apply(thisArg, argsArray);
CallWhat it does
Math.max.apply(null, numbers)Pass every number in the array numbers to Math.max as a separate argument.
describe.apply(user, ["Paris", "France"])Same as describe.call(user, "Paris", "France"), with the arguments in an array.
countArgs.apply(null)No second argument means the function runs with no arguments.

Built into JavaScript (ES3). Every function has it; no import required. Siblings: bind(), call() and toString().

Library declarations
JavaScript
// Function.prototype.apply (ES3)
func.apply(thisArg)
func.apply(thisArg, argsArray)

// returns whatever func returns

Parameters

ParameterDescription
thisArgOptional. The value that this has inside the function. In strict mode it is used exactly as you pass it. In normal (non-strict) code, null and undefined are replaced by the global object. An arrow function ignores it.
argsArrayOptional. An array, or an array-like object (an object with a length and numbered keys), that holds the arguments. null and undefined mean "no arguments". A number, a string or true throws a TypeError.

Return Value

Return ValueDescription
The function's resultWhatever the function returns is returned by apply().
TypeError (thrown)argsArray is not an array, not an array-like object, and not null or undefined.
RangeError (thrown)The array is extremely long, so the engine cannot pass that many arguments.

JavaScript Examples

Example 1 — Use an Array as the Argument List

Math.max() wants separate numbers, but the scores are in an array. apply() unpacks the array for it.

JavaScript
const scores = [72, 95, 64, 88];

console.log(Math.max.apply(null, scores));
console.log(Math.min.apply(null, scores));

const same = Math.max(...scores) === Math.max.apply(null, scores);
console.log("Same as spread: " + same);
Try It Yourself

How It Works

  1. Unpack the array. Math.max.apply(null, scores) calls Math.max(72, 95, 64, 88). The array items become separate arguments.
  2. null for this. Math.max does not use this, so null is fine as the first argument.
  3. Modern alternative. Math.max(...scores) does the same thing, so the comparison prints true.

Example 2 — Choose this and Pass an Array

The describe() function needs a this object and two values. apply() sets both in one call.

JavaScript
function describe(city, country) {
  return this.name + " lives in " + city + ", " + country;
}

const mia = { name: "Mia" };
const leo = { name: "Leo" };

const address = ["Paris", "France"];

console.log(describe.apply(mia, address));
console.log(describe.apply(leo, ["Rome", "Italy"]));
console.log(describe.call(mia, "Paris", "France") === describe.apply(mia, address));
Try It Yourself

How It Works

  1. Two jobs in one call. describe.apply(mia, address) sets this to mia and passes the items of address as city and country.
  2. Any array works. The second call writes the array right inside the parentheses, and the result uses leo.
  3. Same as call(). call() with separate arguments and apply() with an array give an equal result, so the last line prints true.

Example 3 — See Which Argument Lists Are Allowed

The function below counts its arguments. Try different values as the second argument of apply().

JavaScript
function countArgs() {
  return arguments.length;
}

console.log("No second argument: " + countArgs.apply(null));
console.log("null: " + countArgs.apply(null, null));
console.log("Array of 3: " + countArgs.apply(null, [1, 2, 3]));
console.log("Array-like: " + countArgs.apply(null, { length: 2 }));

try {
  countArgs.apply(null, 5);
} catch (err) {
  console.log("A number: " + err.name);
}

try {
  countArgs.apply(null, "abc");
} catch (err) {
  console.log("A string: " + err.name);
}
Try It Yourself

How It Works

  1. Nothing to pass. No second argument, null and undefined all mean "no arguments", so the function counts 0.
  2. Arrays and array-likes. An array of three items gives 3. An object with only { length: 2 } also works and gives 2, because apply() reads the length and treats the missing items as undefined.
  3. Other types fail. A number or a string is not an array-like object, so apply() throws a TypeError. The catch blocks print the error name.

Browser & Runtime Support

apply() is one of the oldest JavaScript features. Every browser and every Node.js version supports it, and it accepts an array-like object in all current engines.

✓ ES3 · Works everywhere

func.apply()

Supported in all browsers, including old ones, and in Node.js, Deno and Bun.

ES3 Standard since
Google Chrome All versions · Desktop & Mobile
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Opera All versions
Full support
Samsung Internet All versions · Android
Full support
Android WebView All versions
Full support
Node.js All versions · Server runtime
Supported
Deno All versions · JavaScript runtime
Supported
Bun All versions · JavaScript runtime
Supported
Internet Explorer All versions
Full support
func.apply() Excellent

Bottom line: You can use apply() anywhere. Very old engines (before ES5) only accepted real arrays and the arguments object as the second argument.

Frequently Asked Questions

It runs a function immediately, with the value you choose as this and with the arguments taken from an array. It returns whatever the function returns. You write it as myFunction.apply(thisValue, [arg1, arg2]).
Only how the arguments are passed. apply() takes one array (fn.apply(obj, [1, 2, 3])); call() takes them one by one (fn.call(obj, 1, 2, 3)). A simple way to remember it: "A" in apply stands for array.
Often not. Math.max(...numbers) does what Math.max.apply(null, numbers) does. apply() is still useful when you also need to set this, and you will see it in a lot of older code, so it is worth knowing.
The function simply runs with no arguments. null and undefined are both allowed as the second argument. A number, a string or a boolean is not allowed and throws a TypeError.
Every item becomes one argument, and engines limit how many arguments one call can have. For arrays with hundreds of thousands of items, loop over the array or use reduce() instead of passing everything to apply().

Next: bind()

Learn how to create a new function whose this value is locked, so it works as a callback.

bind() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful