Favorites

JavaScript Array.of() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.of()
JavaScript Array Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Array.of() static method creates a new array from its arguments, avoiding the single-number quirk of the Array() constructor.

Description

The Array.of() static method creates an array from whatever arguments you pass. It exists because of a quirk in the Array() constructor: Array(3) creates an empty array of length 3, but Array.of(3) creates [3]. In everyday code, an array literal is simpler.

It exists mainly for completeness and for subclasses of Array: MyArray.of(1, 2) creates an instance of the subclass, which a literal can't do. It's also occasionally useful as a function reference, for example passing Array.of where a function that collects its arguments into an array is expected.

Every argument becomes one element, whatever its type, so Array.of(undefined) is an array with one undefined element and Array.of([1, 2]) is an array containing one nested array. To build an array from an existing iterable or array-like object, use Array.from() instead.

Syntax

Array.of(element1, element2, ...)

Parameters

  • element1, element2, ...The elements of the new array.

Return Value

A new array.

Example

console.log(Array.of(3));
console.log(Array(3));
console.log(Array.of(1, 'two', { three: 3 }));

Browser Support

The following information will show you the current browser support for the Array.of() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee