JavaScript Array from() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Array

Definition

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).

Remember
Array.from(source)
Array.from(source, mapFn)

Array.from("JS")           → ["J", "S"]
Array.from(new Set([1,1,2])) → [1, 2]
Array.from({ length: 3 }, (_, i) => i) → [0, 1, 2]

static — call Array.from(...), not arr.from(...)
returns a new array

Syntax

Call Array.from. Start with this line.

JavaScript
Array.from(source, mapFn?, thisArg?)
CallWhat it does
Array.from(source, mapFn?, thisArg?)Primary signature.
Array.from(...)Call with the arguments your case needs.

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

Library declarations
JavaScript
Array.from(source, mapFn?, thisArg?)

Parameters

ParameterDescription
sourceRequired. Iterable or array-like input
mapFnOptional. Transform each item while building
thisArgOptional. this for mapFn

Return Value

Return ValueDescription
*New dense Array

JavaScript Examples

Example 1 — String to Character Array

Turn a string into a real array of characters.

JavaScript
const chars = Array.from("Code");

console.log(chars);
// ["C", "o", "d", "e"]

console.log(Array.isArray(chars));  // true
Try It Yourself

How It Works

  1. Iterable source. Strings yield one character at a time.
  2. Build a real Array. Each character becomes an element.
  3. Static call. You invoke Array.from, not a method on the string.
  4. Array methods ready. You can map, filter, etc. on the result.

Example 2 — Set to Array (Unique Values)

Convert a Set into an array—duplicates are already gone.

JavaScript
const unique = new Set([1, 2, 2, 3]);
const arr = Array.from(unique);

console.log(arr);
// [1, 2, 3]
Try It Yourself

How It Works

  1. Set holds uniques. The second 2 never entered the Set.
  2. Iterate the Set. Array.from reads each unique value.
  3. New array. Order follows insertion order of the Set.
  4. Handy pattern. Array.from(new Set(list)) dedupes a list.

Example 3 — Map While Creating

The second argument transforms each value as the array is built.

JavaScript
const doubled = Array.from([1, 2, 3], (n) => n * 2);

console.log(doubled);
// [2, 4, 6]

const indexes = Array.from({ length: 3 }, (_, i) => i);
console.log(indexes);
// [0, 1, 2]
Try It Yourself

How It Works

  1. mapFn on values. Each source item is doubled before push.
  2. Array-like length. { length: 3 } has slots 0..2 (empty).
  3. Use the index. (_, i) => i fills [0, 1, 2].
  4. One step. Similar to Array.from(x).map(fn), but in one call.

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 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.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.

Next: Array.isArray()

Learn how to reliably check whether a value is an array.

isArray() tutorial →

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