JavaScript Apply() Function Last Updated : 26 May, 2023 Comments Improve Suggest changes Like Article Like Report 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 aboveEdge 12 and aboveFirefox 1 and aboveInternet Explorer 5.5 and aboveOpera 4 and aboveSafari 1 and above Comment More infoAdvertise with us Next Article JavaScript Apply() Function R riarawal99 Follow Improve Article Tags : JavaScript Web Technologies Similar Reads JavaScript Handler apply() Method JavaScript handler.apply() method in JavaScript is used as a trap for a function call. The value returned by this method is used as the result of a function call through a proxy. Syntax: const p = new Proxy(target, { apply: function(target, thisArg, argumentsList) { } }); Parameters: This method acc 2 min read JavaScript Reflect apply() Method Javascript Reflect.apply() method is a standard build-in object in JavaScript which is used to call a function using the specified argument. It works similar to the Function.prototype.apply() method to call a function, but in an efficient manner and easy to understand. Syntax: Reflect.apply(target, 2 min read What is the difference between call and apply in JavaScript ? JavaScript call() Method: It calls the method, taking the owner object as an argument. The keyword this refers to the 'owner' of the function or the object it belongs to. We can call a method that can be used on different objects. Syntax: object.objectMethod.call( objectInstance, arguments ) JavaScr 2 min read Java Collection toArray() Method The toArray() method of Java Collection returns an array containing elements that are inside the calling collection. This article will discuss the toArray() method, its syntaxes, how it works, and some code examples. Syntax of toArray() MethodObject[] toArray();Return Type: The return type of the ab 3 min read Java 8 Features - Complete Tutorial Java 8 is the most awaited release of the Java programming language development because, in the entire history of Java, it has never released that many major features. It consists of major features of Java. It is a new version of Java and was released by Oracle on 18 March 2014. Java provided suppor 9 min read HashMap replaceAll(BiFunction) method in Java with Examples The replaceAll(BiFunction) method of HashMap class replaces each value with the result of applying the given function(performs a certain operation) on the corresponding value. This process continues in the same manner until all the entries have been processed or until an exception is thrown by the f 3 min read CopyOnWriteArrayList set() method in Java with Examples The set(E e) method in the class CopyOnWriteArrayList class replaces the element at the specified index with the element provided as a parameter to the method. The method returns the element that has been replaced by the new element.Syntax: public E set(int index, E element) Parameters: The method t 2 min read CopyOnWriteArrayList addAllAbsent() method in Java with Examples The addAllAbsent(E e) method of CopyOnWriteArrayList appends all of the elements in the specified collection that are not already contained in this list, to the end of this list, in the order that they are returned by the specified collection's iterator. Syntax: public int addAllAbsent(Collection 2 min read How to Evaluate Math Expression Given in String Form in Java? Evaluating a mathematical expression given in string form is a common task in Java programming, often encountered in applications involving mathematical computations or user input processing. One approach involves using the ScriptEngine class from the javax.script package, which allows for the dynam 4 min read Java | BiFunction Interface methods - apply() and andThen() The BiFunction Interface is a part of the java.util.function package which has been introduced since Java 8, to implement functional programming in Java. It represents a function which takes in two arguments and produces a result. Hence this functional interface which takes in 3 parameters namely:-T 5 min read Like