Array.from() is a static method that builds a real array from iterables (strings, Sets, Maps) or array-like objects (NodeList, arguments). Optional map function transforms items during creation. This tutorial covers syntax, five examples, pitfalls with plain objects, and comparisons with spread and Object.values().
01
Syntax
Array.from(src)
02
Static
On Array
03
Iterable
String, Set
04
Array-like
length + index
05
Map fn
2nd argument
06
ES2015
Modern JS
Fundamentals
Introduction
Not everything in JavaScript is a true Array, even when it behaves like one. DOM node lists, the legacy arguments object, and strings can be iterated but lack array methods like map() or filter().
Array.from() converts those sources into a genuine array so you can use the full array toolkit. You can also pass a mapping function to transform values in the same step.
Concept
Understanding the Array.from() Method
Array.from(arrayLike, mapFn?, thisArg?) creates a new, shallow-copied array. The source must be either iterable (implements Symbol.iterator) or array-like (has length and indexed properties from 0 to length - 1).
The optional mapFn works like map() during construction—handy for squaring numbers or uppercasing strings without a separate pass.
💡
Beginner Tip
Plain objects like { a: 1, b: 2 } are not array-like. Use Object.values(obj) to get an array of values instead of Array.from(obj).
Foundation
📝 Syntax
General form of the static method:
JavaScript
Array.from(arrayLike, mapFunction, thisArg)
Parameters
arrayLike — iterable or array-like object to convert.
mapFunction — optional; called on each element (element, index).
Plain objects lack length and numeric indices. Object.values(), Object.keys(), or Object.entries() extract data correctly.
Applications
🚀 Common Use Cases
DOM NodeList — convert query results to arrays for map/filter.
Set to array — dedupe then process as a list.
String processing — character arrays for algorithms or UI.
Range generation — { length: n } plus map callback.
Clone iterables — shallow copy into a mutable array.
Map during copy — transform while converting (square, parse, format).
🧠 How Array.from() Runs
1
Inspect source
Check if iterable or array-like (has length).
Validate
2
Collect elements
Iterate or read indices 0…length−1.
Read
3
Apply mapFn
Optional second argument transforms each item.
Transform
4
📦
Return new Array
Real array ready for all instance methods.
Important
📝 Notes
Static method—call Array.from(), not on an instance.
Works on iterables and array-likes; not plain objects.
Second argument is optional map—not the same as Array.from(arr, 2) depth.
Shallow copy only; nested objects are shared references.
[...iterable] is fine for iterables but not array-likes without iterator.
ES2015—polyfill needed for IE11.
Compatibility
Browser & Runtime Support
Array.from() was added in ES2015 (ES6). It is available in all evergreen browsers and modern Node.js versions.
✓ Baseline · ES2015
Array.from()
Supported in Chrome 45+, Firefox 32+, Safari 9+, Edge (all versions), and Node 4+. Not available in Internet Explorer without a polyfill.
97%Modern browser support
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.from()Excellent
Bottom line: Safe for modern web apps. For IE11, use a polyfill or legacy slice.call patterns.
Wrap Up
Conclusion
Array.from() bridges the gap between array-like or iterable data and real JavaScript arrays. Use it for DOM lists, Sets, strings, and clever range generation—and reach for Object.values() when the source is a plain object.
Next, learn Array.isArray() to reliably test whether a value is a true array.
Use for NodeList, Set, string, and array-like objects
Pass map fn as 2nd arg when transforming during copy
Use Object.values/keys/entries for plain objects
Prefer Array.from({ length: n }, fn) for ranges
Feature-detect or polyfill for legacy IE
❌ Don’t
Call Array.from on arbitrary objects expecting values
Confuse it with instance methods like map
Assume deep clone—copy is shallow
Use when [...arr] on an array is enough
Forget spread cannot handle all array-likes
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about Array.from()
Turn iterables and array-likes into real arrays.
5
Core concepts
📝01
Static
Array.from(src)
API
🔀02
Iterable
String, Set.
Source
📐03
Array-like
length + index.
DOM
📊04
Map fn
2nd argument.
Transform
⚠05
Not objects
Use Object.values.
Pitfall
❓ Frequently Asked Questions
Array.from() creates a new real Array from an iterable or array-like object (something with length and indexed properties). You can optionally pass a map function to transform items while building the array.
It is a static method on the Array constructor. You call Array.from(source), not someArray.from(source).
An object with a length property and indexed keys like 0, 1, 2. Examples include the arguments object, DOM NodeList, and strings (which are also iterable).
Not directly. Plain objects like { a: 1, b: 2 } are neither iterable nor array-like unless they have length and numeric keys. Use Object.values(), Object.keys(), or Object.entries() instead.
Both work on iterables like strings, Sets, and arrays. Array.from() also supports array-like objects and accepts an optional map function as the second argument.
Array.from() is ES2015 (ES6). It works in all modern browsers and Node.js. Internet Explorer does not support it without a polyfill.
Did you know?
Array.from({ length: 3 }) without a map function produces [undefined, undefined, undefined] because the slots are empty. Add a map callback to fill meaningful values—like (_, i) => i for [0, 1, 2].