The array.of() function is an inbuilt function in JavaScript which creates a new array instance with variables present as the argument of the function.
Syntax: Array.of(element0, element1, ....)
Parameters:
Parameters present are element0, element1, …. which are basically an element for which the array creation is done.
Return Value:
It simply returns a new Array instance.
Browser Support:
Here 2nd column contained int values are verson of the corresponding browser.

Examples:
Input: Array.of(10, 20, 30) Output: > Array [10, 20, 30]
Explanation:
Here in input arguments of the array.of() function are numbers converted into an array
containing the same argument shown in the output.
Input: Array.of("Ram","Geeta")
Output: > Array ["Ram", "Geeta"]
Explanation:
Here in input arguments of the array.of() function are string converted into an array
containing the same argument shown in the output.
Let’s see JavaScripts program on Array.of() function:
// Here the Array.of() method creates a new Array instance with // a variable number of arguments, regardless of // number or type of the arguments. console.log(Array.of(0, 0, 0)); console.log(Array.of(11, 21, 33)); console.log(Array.of("Ram","Geeta")); console.log(Array.of('geeksforgeeks')); console.log(Array.of(2,3,4,'Sheeta')); |
Output:
> Array [0, 0, 0] > Array [11, 21, 33] > Array ["Ram", "Geeta"] > Array ["geeksforgeeks"] > Array [2, 3, 4, "Sheeta"]
Application:
Whenever we need to get elements of any array that time we take help of Array.of() method in JavaScript.
console.log(Array.of(['Ram', 'Rahim', 'Geeta', 'Sheeta'])); |
Output:
> Array [Array ["Ram", "Rahim", "Geeta", "Sheeta"]]
Recommended Posts:
- JavaScript Course | Understanding Code Structure in JavaScript
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | What is JavaScript ?
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- How to get the function name from within that function using JavaScript ?
- How to call a function that return another function in JavaScript ?
- How to Check a Function is a Generator Function or not using JavaScript ?
- JavaScript | Math.ceil( ) function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : Akanksha_Rai


