In JavaScript, Array.from(source) is a static method that builds a new Array from an iterable (string, Set, Map, array) or an array-like object (length + indexes). Optional second argument maps each item while creating (ES2015).
mapFn on values. Each source item is doubled before push.
Array-like length.{ length: 3 } has slots 0..2 (empty).
Use the index.(_, i) => i fills [0, 1, 2].
One step. Similar to Array.from(x).map(fn), but in one call.
Compatibility
Browser & Runtime Support
Array.from() is part of ES2015 (ES6). It is available in all evergreen browsers and Node.js; Internet Explorer needs a polyfill.
✓ Baseline · ES2015
Array.from()
Supported in Chrome 45+, Firefox 32+, Safari 9+, Edge 12+, and Node 4+. Not available in Internet Explorer without a polyfill.
96%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 and current Node releases. For IE11, ship a polyfill or feature-detect with typeof Array.from === "function".
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.