Favorites

JavaScript Array.from() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.from()
JavaScript Array Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

The Array.from() static method creates a new array from an iterable or array-like object, such as a string, Set or NodeList, optionally mapping each element.

Description

The Array.from() static method creates a new array from any iterable or array-like object. It converts things like a NodeList from querySelectorAll(), the characters of a string, the values of a Set or the entries of a Map into a real array with all the array methods.

The optional mapping function runs on each element as it is added. Combined with an object that only has a length, Array.from({ length: 5 }, (_, i) => i) is a neat way to generate a sequence of numbers.

Array.from() also accepts the result of map.entries(), set.values() and generator functions, and works on typed arrays to create regular arrays. Unlike spread syntax, which only works with iterables, it also handles array-like objects that aren't iterable, such as { length: 2, 0: 'a', 1: 'b' }. Array.fromAsync() does the same for async iterables, returning a promise.

Syntax

Array.from(arrayLike)
Array.from(arrayLike, mapFn)
Array.from(arrayLike, mapFn, thisArg)

Parameters

  • arrayLikeAn iterable (such as a string, Set, Map or NodeList) or an object with a length property.
  • mapFnOptional. A function to call on every element, like map().
  • thisArgOptional. A value to use as this inside mapFn.

Return Value

A new array.

Example

console.log(Array.from('hello'));
console.log(Array.from(new Set([1, 1, 2])));
console.log(Array.from({ length: 5 }, (_, i) => i * 2));
console.log(Array.from([1, 2, 3], n => n * n));

Browser Support

The following information will show you the current browser support for the Array.from() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee