Friday, October 24, 2025
HomeLanguagesJavascriptJavaScript Apply() Function

JavaScript Apply() Function

The apply() method is used to write methods, which can be used on different objects. It is different from the function call() because it takes arguments as an array. 

Syntax:

apply()

Return Value: It returns the method values of a given function. 

Example 1: This example illustrates the apply() function without arguments. 

Javascript




let student = {
    details: function () {
        return this.name + this.class;
    }
}
let stud1 = {
    name: "Dinesh",
    class: "11th",
}
let stud2 = {
    name: "Vaibhav",
    class: "11th",
}
 
let x = student.details.apply(stud2);
console.log(x);


Output:

Vaibhav
11th

Example 2: This example illustrates the apply() function with arguments. 

Javascript




let student = {
    details: function (section, rollnum) {
        return this.name + this.class
            + " " + section + rollnum;
    }
}
let stud1 = {
    name: "Dinesh",
    class: "11th",
}
let stud2 = {
    name: "Vaibhav",
    class: "11th",
}
 
let x = student.details.apply(stud2, ["A", "24"]);
console.log(x);


Output:

Vaibhav
11th A
24

 Supported Browser: 

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 5.5 and above
  • Opera 4 and above
  • Safari 1 and above
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS