JavaScript (ES2026) reference · Array Methods
JavaScript Array.from() Method
Create a new array from an iterable or array-like object, with an optional function to map each element.
JavaScript (ES2026) Since ES2015
Syntax
Array.from(items, mapFn, thisArg)
Parameters
| Parameter | Description |
|---|---|
items |
An iterable (string, Set, Map, …) or array-like object (has length). |
mapFn optional |
Called on each element. |
Return value
A new array.
Examples
console.log(Array.from("hey"));
console.log(Array.from(new Set([1, 1, 2])));
Output
[ 'h', 'e', 'y' ] [ 1, 2 ]
console.log(Array.from({ length: 5 }, (_, i) => i * i));
Output
[ 0, 1, 4, 9, 16 ]
const map = new Map([["a", 1], ["b", 2]]);
console.log(Array.from(map), Array.from(map.keys()));
Output
[ [ 'a', 1 ], [ 'b', 2 ] ] [ 'a', 'b' ]
Version history
| Version | Change |
|---|---|
| JavaScript ES2015 | Added |
In other languages
list()· Python
Related
Array.of()· Create a new array from its arguments. Unlike Array(3), Array.of(3) makes [3], not an empty array of length 3.Array.isArray()· Return true if a value is an array. More reliable than typeof, which reports 'object' for arrays.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial