What is the use of the Array.of() method in JavaScript ?
Last Updated :
31 Jan, 2024
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
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' ]
Share your thoughts in the comments
Please Login to comment...