English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Array from() Method

The from() method is used to create a new, shallow-copied array instance from a class array or iterable object.

 JavaScript Array Object

 The from() method is used to create a new, shallow-copied array instance from a class array or iterable object.

Note:from()methodlengthThe attribute is1.

Syntax:

Array.from(object, mapFunction, thisArg)
var array = Array.from("w3codebox);
document.getElementById("result").innerHTML = array;
Test and See‹/›

Browser compatibility

The numbers in the table specify the first browser version that fully supports the from() method:

method
from()4532is912

parameter value

parameterdescription
object(Required) An iterable or array-like object to be converted to an array
MapFunction(Optional) Map function to call each element of the array
thisArg(Optional) ExecuteMapFunctionis used asThisValue

Technical Details

Return Value:A new Array example
JavaScript Version:ECMAScript 6

More Examples

This example creates an array from a string, then iterates over it:

var arr = Array.from("w3codebox);
var result = document.getElementById("result");
for (let i = 0; i < arr.length; i++) {
result.innerHTML = result.innerHTML + 'arr[' + i + '] = ' + arr[i] + '<br>';
}
Test and See‹/›

 JavaScript Array Object