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() function is 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 is a string converted into an array containing the same argument shown in the output.
Array [0, 0, 0] Array [11, 21, 33] Array ["Ram", "Geeta"] Array ["geeksforgeeks"] Array [2, 3, 4, "Sheeta"]
Array [Array ["Ram", "Rahim", "Geeta", "Sheeta"]]
Array.of( ) function 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( ) function is supported in the browser or not.
- Now create a function expression named Array.of( ) . This function 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.
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
Please Login to comment...