JavaScript Array.from()
Example
Create an array from a string:
Array.from(text);
More examples below !
Description
The Array.from() method returns an array from any object with a length property.
The Array.from() method returns an array from any iterable object.
Note
Array.from() is a static property of the JavaScript Array object.
You can only use it as Array.from().
Using x.from(), where x is an array will return undefined.
Syntax
Parameters
The object to convert to an array.
A map function to call on each item.
A value to use as
thisfor the mapFunction
Return Value
More Examples
Example
Create an array from an array:
const myArr = Array.from(myNumbers, (x) => x * 2);
Array Tutorials:
Browser Support
Array.from() is an ECMAScript6 (ES6 2015) feature.
JavaScript 2015 is supported in all browsers since June 2017:
| Chrome 51 |
Edge 15 |
Firefox 54 |
Safari 10 |
Opera 38 |
| May 2016 | Apr 2017 | Jun 2017 | Sep 2016 | Jun 2016 |