JavaScript Array of() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

In JavaScript, Array.of(...elements) is a static method that creates a new array from the arguments you pass. Every argument becomes one element — even a single number. Call Array.of(...), not arr.of(...). To build an array from an iterable or array-like value, use Array.from().

Remember
Array.of(element0, element1, …)

Array.of(1, 2, 3)   → [1, 2, 3]
Array.of(7)         → [7]          // one element
Array(7)            → [empty × 7]  // length 7 (constructor quirk)
Array.of()          → []

static method on Array
arguments → elements (always)

Syntax

Call Array.of. Start with this line.

JavaScript
Array.of(e0, e1, …)
CallWhat it does
Array.of(e0, e1, …)Primary signature.
Array.of(...)Call with the arguments your case needs.

Built into JavaScript. Call Array.of(...) on the Array constructor — no import required.

Library declarations
JavaScript
Array.of(e0, e1, …)

Parameters

ParameterDescription
ArgumentsOptional. Become array elements (none → [])

Return Value

Return ValueDescription
*New array

JavaScript Examples

Example 1 — Create an Array from Arguments

Pass the values you want as elements.

JavaScript
const nums = Array.of(1, 2, 3);
const mixed = Array.of("JS", true, null);
const empty = Array.of();

console.log(JSON.stringify(nums));    // [1,2,3]
console.log(JSON.stringify(mixed));   // ["JS",true,null]
console.log(JSON.stringify(empty));   // []
console.log(Array.isArray(nums));     // true
Try It Yourself

How It Works

  1. Arguments → elements. Order is preserved.
  2. Any type works. Strings, booleans, null are fine.
  3. No args. You get a normal empty array.
  4. Real array. Array.isArray(nums) is true.

Example 2 — Array.of(7) vs Array(7)

A single number is the classic reason to prefer Array.of.

JavaScript
const withOf = Array.of(7);
const withCtor = Array(7);

console.log(JSON.stringify(withOf));  // [7]
console.log(withOf.length);           // 1

console.log(withCtor.length);         // 7
console.log(0 in withCtor);           // false (empty slot)
Try It Yourself

How It Works

  1. Array.of(7). Creates one element: the number 7.
  2. Array(7). Treats 7 as a length, not a value.
  3. Empty slots. Constructor result has length but no index 0.
  4. Rule of thumb. Want [n] → use Array.of(n) or [n].

Example 3 — Wrap Spread Arguments

Turn a list of values (or function args) into an array safely.

JavaScript
function collect(...values) {
  return Array.of(...values);
}

console.log(JSON.stringify(collect(10, 20)));     // [10,20]
console.log(JSON.stringify(collect(5)));          // [5]
console.log(JSON.stringify(Array.of(...[9, 8]))); // [9,8]
Try It Yourself

How It Works

  1. Rest params. ...values gathers the call arguments.
  2. Array.of spreads them. Each value becomes one element.
  3. Single number stays an element. collect(5) → [5], not length 5.
  4. Spread an array. Array.of(...[9, 8]) copies those values into a new array.

Browser & Runtime Support

Array.of() is part of ES2015 (ES6). It has been available in evergreen browsers and Node.js for years.

✓ Baseline · ES2015

Array.of()

Supported in Chrome 45+, Firefox 25+, Safari 9+, Edge 12+, and Node.js 4+. Not available in Internet Explorer without a polyfill.

98% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
Array.of() Excellent

Bottom line: Safe for modern web apps and Node LTS. For IE11, feature-detect with if (typeof Array.of === "function") or use a polyfill / array literal.

Frequently Asked Questions

Array.of() creates a new array whose elements are the arguments you pass in. Each argument becomes one array element, with no special constructor rules.
It is a static method on the Array constructor. Call Array.of(1, 2, 3), not someArray.of(1, 2, 3).
Array(7) creates an array with length 7 and empty slots. Array.of(7) creates [7] — one element with value 7.
For everyday code, literals like [1, 2, 3] are fine. Use Array.of when a single number must be an element, or when wrapping arguments: Array.of(...values).
An empty array: []. It never creates a length-only sparse array.
Array.of() is ES2015 (ES6). It works in all modern browsers and Node.js. Internet Explorer needs a polyfill.

Next: Array methods

Browse the full JavaScript Array method list.

Array overview →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful