JavaScript Array from() Method

Beginner
⏱️ 9 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Static method

What You’ll Learn

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

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.

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

📝 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).
  • thisArg — optional this for mapFunction.

Return value

  • A new Array instance.
  • Shallow copy of elements from the source.
  • Source object is not modified.

Common patterns

  • Array.from("hi") — string to character array.
  • Array.from(new Set(arr)) — Set to array (dedupe).
  • Array.from(nodeList) — DOM NodeList to array.
  • Array.from({ length: 5 }, (_, i) => i) — generate range.

⚡ Quick Reference

GoalCode
Iterable to arrayArray.from(iterable)
Map while convertingArray.from(src, fn)
Generate 0…n−1Array.from({ length: n }, (_, i) => i)
Plain object valuesObject.values(obj)
Called onArray (static)

📋 Array.from() vs spread [...] vs Object.values()

Pick the tool that matches your source type and whether you need a map step.

Array.from
iterable + array-like

Optional map fn

spread
[...iterable]

Iterables only

Object.values
plain object

Property values

slice.call
legacy

Pre-ES2015

Examples Gallery

Open DevTools Console (F12) or use Try-it labs. Example N maps to ?tryit=N.

📚 Getting Started

Convert common iterable sources.

Example 1 — String to Character Array

Strings are iterable—Array.from turns each character into an array element.

JavaScript
const greeting = "Hello";

const chars = Array.from(greeting);

console.log(chars);
// ["H", "e", "l", "l", "o"]
Try It Yourself

How It Works

Each UTF-16 code unit becomes one array slot. For emoji or complex Unicode, consider [...str] or Intl.Segmenter for graphemes.

Example 2 — Set to Array with Mapping

Convert a Set and uppercase each value in one call.

JavaScript
const fruits = new Set(["apple", "orange", "banana"]);

const upper = Array.from(fruits, (fruit) => fruit.toUpperCase());

console.log(upper);
// ["APPLE", "ORANGE", "BANANA"]
Try It Yourself

How It Works

The second argument replaces Array.from(set).map(fn) with a single efficient step.

📈 Practical Patterns

Array-like objects, ranges, and object pitfalls.

Example 3 — Array-Like Object to Real Array

Objects with length and numeric keys can become true arrays.

JavaScript
const arrayLike = { 0: "a", 1: "b", 2: "c", length: 3 };

const arr = Array.from(arrayLike);

console.log(arr);
// ["a", "b", "c"]
console.log(Array.isArray(arr));
// true
Try It Yourself

How It Works

This pattern matches DOM NodeList and the legacy arguments object. After conversion, use map, filter, and other array methods freely.

Example 4 — Generate a Range with { length: n }

A clever trick: array-like length with a map function builds sequences without loops.

JavaScript
const oneToFive = Array.from({ length: 5 }, (_, index) => index + 1);

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

How It Works

{ length: 5 } is array-like with empty slots. The map callback receives (value, index) for each index from 0 to 4.

Example 5 — Plain Objects Need Object.values()

Array.from() on a normal object returns an empty array—use the right tool.

JavaScript
const scores = { math: 90, english: 85, science: 92 };

console.log(Array.from(scores));
// []

console.log(Object.values(scores));
// [90, 85, 92]
Try It Yourself

How It Works

Plain objects lack length and numeric indices. Object.values(), Object.keys(), or Object.entries() extract data correctly.

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

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

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 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. For IE11, use a polyfill or legacy slice.call patterns.

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.

💡 Best Practices

✅ Do

  • 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

Key Takeaways

Knowledge Unlocked

Five things to remember about Array.from()

Turn iterables and array-likes into real arrays.

5
Core concepts
🔀 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].

Continue to isArray()

Learn the reliable way to check whether a value is a true JavaScript 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.

6 people found this page helpful