Open In App

What is the use of the Array.of() method in JavaScript ?

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The JavaScript array.of() method is an inbuilt method in JavaScript that creates a new array instance with variables present as the argument of the method.

Example: Here, Array.of() method is used to create new array instances with a variable number of arguments.

Javascript




// 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

[ 0, 0, 0 ]
[ 11, 21, 33 ]
[ 'Ram', 'Geeta' ]
[ 'geeksforgeeks' ]
[ 2, 3, 4, 'Sheeta' ]

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads