目录

JavaScript Array.from()

Example

Create an array from a string:

Array.from("ABCDEFG")
Try it Yourself »

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.

Array.from()

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

Array.from( object, mapFunction, thisValue)

Parameters

Parameter Description
object Required.
The object to convert to an array.
mapFunction Optional.
A map function to call on each item.
thisValue Optional.
A value to use as thisfor the mapFunction

Return Value

Type Description
An array The values from the iterable object.

Browser Support

Array.from() is an ECMAScript6 (ES6) feature.

ES6 (JavaScript 2015) is supported in all modern browsers:

Chrome Edge Firefox Safari Opera
Yes Yes Yes Yes Yes

Array.from() is not supported in Internet Explorer 11 (or earlier).