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.
Input: Array.of(10, 20, 30)
Output: Array [10, 20, 30]
Explanation: Here in input arguments of the array.of() method is numbers converted into an array containing the same argument shown in the output.
Output: Array ["Ram", "Geeta"]
Explanation: Here in input arguments of the array.of() method is a string converted into an array containing the same argument shown in the output.
console.log(Array.of(0, 0, 0));
console.log(Array.of(11, 21, 33));
console.log(Array.of(2, 3, 4,
Array [0, 0, 0]
Array [11, 21, 33]
Array ["Ram", "Geeta"]
Array [2, 3, 4, "Sheeta"]
Array [Array ["Ram", "Rahim", "Geeta", "Sheeta"]]
Array.of( ) method does not support by the Internet Explorer browser. As a developer, it’s your responsibility to provide a code that runs everywhere ( browser in this case ).
So let’s see how to create a polyfill for Array.of( )
- Check if the Array.of( ) method is supported in the browser or not.
- Now create a method expression named Array.of( ) . This method takes the items of the array.
- Now create an array and push all the argument items into it.
- Now return the array created by you.
let newArr = ;
Array.of(1, 2, 3, 4, 5, 6)
[1, 2, 3, 4, 5, 6]
Array.of("John", "Doe", "Smith", "Ram")
["John", "Doe", "Smith", "Ram"]
- Chrome 45 and above
- Edge 12 and above
- Firefox 25 and above
- Opera 26 and above
- Safari 9 and above
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses
are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!