JavaScript Function apply() method

The JavaScript Function apply() method is used to call a function contains this value and an argument contains elements of an array. Unlike call() method, it contains the single array of arguments.

Syntax

Parameter

thisArg - It is optional. The this value is given for the call to a function.

array - It is optional. It is an array-like object.

Return Value

It returns the result of the calling function along provided this value and arguments.

JavaScript Function apply() method Example

Example 1

Let's see an example to determine the maximum element.

Test it Now

Output:

9

Example 2

Let's see an example to determine the minimum element.

Test it Now

Output:

1

Example 3

Let's see an example to join arrays of same type.

Test it Now

Output:

1,2,3,4,5,6,7,8

Example 4

Let's see an example to join array of different type.

Test it Now

Output:

1,2,3,4,One,Two,Three,Four





Latest Courses