JavaScript Array of Functions



The Array.of() method of JavaScript is used to create a new array instance with variables as parameter values.

The syntax is as follows −

Array.of(elements....)

Above, elements are the values as parameter values.

Let us now implement the Array.of() method in JavaScript −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
   <h2>Demo Heading</h2>
   <p>Click the button to display the values in Console</p>
   <button onclick="display()">Result</button>
   <p id="test"></p>
   <script>
      function display() {
         console.log(Array.of(10, 20, 30, 40 ,50));
      }
   </script>
</body>
</html>

Output

Click the “Result” and check the Console for the output −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
   <h2>Demo Heading</h2>
   <p>Get the student names with top 5 ranks...</p>
   <button onclick="display()">Result</button>
   <p id="test"></p>
   <script>
      function display() {
         console.log(Array.of("Kevin", "Tom", "Ryan", "Jacob", "Jack"));
      }
   </script>
</body>
</html>

Output

Click the “Result” button and check the result in the Console −

Updated on: 2019-12-17T09:32:53+05:30

9K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements