JavaScript Function.prototype.apply() Method
The apply() method calls a function with a given this value and its arguments supplied as an array.
Description
The apply() method calls the function with a chosen this value and the arguments provided as an array. It's the same as call() except for how arguments are passed. Spread syntax has replaced most uses: Math.max.apply(null, nums) can be written Math.max(...nums).
Passing null or undefined as thisArg is common when the function doesn't use this; in non-strict code, this then becomes the global object. The arguments can be any array-like object, such as arguments or a NodeList.
Reflect.apply(fn, thisArg, args) does the same thing and is often used in Proxy handlers. Arrow functions ignore the thisArg, since they don't have their own this.
Syntax
func.apply(thisArg)
func.apply(thisArg, argsArray)Parameters
- thisArgThe value to use as
thisinside the function. - argsArrayOptional. An array (or array-like object) of arguments.
Return Value
The result of calling the function.
Example
Browser Support
The following information will show you the current browser support for the Function.prototype.apply() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





