JavaScript Array.of()
- Previous Page map()
- Next Page pop()
- Go Up One Level JavaScript Array Reference Manual
Definition and Usage
Array.of()
The method creates a new array based on an arbitrary number of parameters.
Array.of()
The method can accept parameters of any type.
Example
Create a new array based on multiple parameters:
let fruits = Array.of("Banana", "Orange", "Apple", "Mango"); document.getElementById("demo").innerHTML = fruits;
Syntax
Array.of(element1, element2, ... , elementN)
Parameter
Parameter | Description |
---|---|
elements | Optional. Any number of elements, of any type. |
Return Value
Type | Description |
---|---|
Array |
A new array created based on the parameter. The parameter can be a string, number, array, or other allowed types. |
Browser Support
of()
It is a feature of ECMAScript6 (ES6).
ES6 (JavaScript 2015) has been supported in all modern browsers since June 2017:
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome 51 | Edge 15 | Firefox 54 | Safari 10 | Opera 38 |
May 2016 | April 2017 | June 2017 | September 2016 | June 2016 |
of()
Not supported in Internet Explorer.
- Previous Page map()
- Next Page pop()
- Go Up One Level JavaScript Array Reference Manual