Array.from()

ES6+

Creates a new Array instance from an array-like or iterable object.

Syntax

Array.from(arrayLike, mapFn, thisArg)

Parameters

arrayLike ArrayLike | Iterable

An array-like or iterable object to convert to an array

mapFn Function optional

Map function to call on every element of the array

Return Value

Array

A new Array instance

Examples

JavaScript
console.log(Array.from('hello'));
console.log(Array.from([1, 2, 3], x => x * 2));
Output:
// ['h', 'e', 'l', 'l', 'o'] [2, 4, 6]

Related Methods