Easy Tutorial
❮ Prop Win Screenleft Prop Style Counterreset ❯

JavaScript from() Method

JavaScript Array Object

Example

Create an array from a string:

var myArr = Array.from("tutorialpro");

Definition and Usage

The from() method returns an array from any object with a length property or an iterable object.

It returns true if the object is an array, otherwise it returns false.


Browser Support

The numbers in the table specify the first browser version that fully supports the method.

Method Chrome Edge Firefox IE Safari
from() 45.0 12.0 32.0 9 25.0

Syntax

Array.from(object, mapFunction, thisValue)

Parameters

Parameter Description
object Required. The object to convert to an array.
mapFunction Optional. A function to call on each element of the array.
thisValue Optional. The value to use as this when executing the mapFunction.

Technical Details

| Return Value: | An array object. | | JavaScript Version: | ECMAScript 6 |


More Examples

The following example returns an array of objects from a set.

var setObj = new Set(["a", "b", "c"]);
var objArr = Array.from(setObj);
objArr[1] == "b";  // true

The following example demonstrates how to change the values of elements using arrow syntax and a mapping function.

var arr = Array.from([1, 2, 3], x => x * 10);
// arr[0] == 10;
// arr[1] == 20;
// arr[2] == 30;

JavaScript Array Object

❮ Prop Win Screenleft Prop Style Counterreset ❯