Array.of() is a static method that builds a new array from the values you pass as arguments. It avoids the confusing behavior of Array(7) (length-only array) versus Array.of(7) ([7]). This tutorial covers syntax, five examples, comparisons, and when to prefer literals or Array.from().
01
Static
Array.of()
02
Arguments
Become elements
03
No quirks
Single number OK
04
Empty call
[]
05
Spread
...values
06
ES2015
Modern browsers
Fundamentals
Introduction
Most of the time you create arrays with literals: [1, 2, 3]. But the legacy Array() constructor has a trap: a single number argument sets length, not the element value. Array.of() was added in ES2015 to create arrays predictably from any list of arguments.
Think of Array.of as “make an array containing exactly these values”—whether you pass zero, one, or many arguments.
Concept
Understanding the Array.of() Method
Array.of(element0, element1, ...) returns a new dense array. Each argument becomes an element at the next index. There is no special case for a lone number: Array.of(5) is [5], not an array of length 5.
This is the counterpart to Array.from(), which builds arrays from iterables or array-like objects. Use of when you already have individual values; use from when converting another collection.
💡
Beginner Tip
For fixed lists in source code, [1, 2, 3] is still the most readable choice. Reach for Array.of when the constructor quirk matters or when spreading dynamic arguments into a new array.
Rest parameters already form an array, but Array.of(...items) is handy when normalizing unknown argument lists into a new copy.
Applications
🚀 Common Use Cases
Single numeric element — Array.of(n) instead of Array(n).
Factory helpers — wrap rest args into a new array copy.
Consistent APIs — always return real arrays from functions.
Testing — build fixture arrays without constructor surprises.
Functional style — pair with spread when composing data pipelines.
Teaching — demonstrate static vs instance Array methods.
🧠 How Array.of() Runs
1
Count arguments
Engine reads how many values were passed.
Input
2
Allocate array
Creates a new dense array with that length.
Create
3
Copy each argument
Assigns argument 0 to index 0, and so on.
Fill
4
📦
Return new array
No length-only sparse trap from a single number.
Important
📝 Notes
Static method—call Array.of(), not on an instance.
Fixes the Array(n) single-number length quirk.
Does not convert iterables—use Array.from() for strings, Sets, etc.
Literals [a, b, c] remain preferred for fixed lists in source code.
Array.of(1, 2) and new Array(1, 2) both yield [1, 2].
ES2015—not available in IE without a polyfill.
Compatibility
Browser & Runtime Support
Array.of() was introduced in ES2015 (ES6) alongside other static Array helpers like Array.from() and Array.isArray().
✓ Baseline · ES2015
Array.of()
Supported in Chrome 45+, Firefox 25+, Safari 9+, Edge (all versions), and all modern Node.js versions. Not supported in Internet Explorer.
97%Modern browsers
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
Array.of()Excellent
Bottom line: Safe in all modern projects. Use a polyfill or literals if you must support Internet Explorer.
Wrap Up
Conclusion
Array.of() creates predictable arrays from arguments, especially when a single number should be an element, not a length. For converting strings or Sets, use Array.from(); for everyday lists, literals still win on readability.
You have now covered all three core static Array helpers. Return to the array methods hub to explore instance methods like at() and map().
Use Array.from for iterables and array-like objects
Spread rest parameters when building copies: Array.of(...args)
Document why you chose of over a literal in edge cases
❌ Don’t
Use Array(n) when you mean [n]
Replace every literal with Array.of for no reason
Expect Array.of to parse strings into characters
Call it on an instance: [1].of(2) does not exist
Confuse Array.of with Array.from
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.of()
Create arrays from arguments without constructor surprises.
5
Core concepts
📝01
Static
Array.of()
API
702
Single number
[7] not length.
Quirk fix
📦03
Empty
[]
Default
🔄04
from
Iterables.
Pair
[]05
Literals
Still common.
Style
❓ 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 seven empty slots (length 7). Array.of(7) creates [7] — one element with value 7. The constructor treats a single number as a length; Array.of always treats arguments as elements.
For everyday code, literals like [1, 2, 3] are fine. Use Array.of when you need predictable behavior with a single numeric value, or when wrapping spread 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 does not support it without a polyfill.
Did you know?
Typed arrays have their own of methods too: Int8Array.of(1, 2, 3) creates a typed array with those values. The same “arguments become elements” rule applies.