JavaScript Array.of()
Examples
Create a new array from a number of arguments:
let fruits = Array.of("Banana", "Orange", "Apple", "Mango");
document.getElementById("demo").innerHTML = fruits;
Try it Yourself »
Description
The Array.of() method creates a new array from any number of arguments.
The Array.of() method can take any type of arguments.
Syntax
Array.of(element1, element2, ... , elementN)
Parameters
| Parameter | Description |
| elements | Optional. Any number of elements regardless of type. |
Return Value
| Type | Description |
| An Array |
A new array created from the arguments. The arguments can be strings, numbers, arrays, or any other allowed type. |
Array Tutorials:
Browser Support
of() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
| Chrome 51 |
Edge 15 |
Firefox 54 |
Safari 10 |
Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |