English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The from() method is used to create a new, shallow-copied array instance from a class array or iterable 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.
Array.from(object, mapFunction, thisArg)
var array = Array.from("w3codebox); document.getElementById("result").innerHTML = array;Test and See‹/›
The numbers in the table specify the first browser version that fully supports the from() method:
method | |||||
from() | 45 | 32 | is | 9 | 12 |
parameter | description |
---|---|
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 |
Return Value: | A new Array example |
---|---|
JavaScript Version: | ECMAScript 6 |
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‹/›