| title | ms.custom | ms.date | ms.prod | ms.reviewer | ms.suite | ms.technology | ms.tgt_pltfrm | ms.topic | dev_langs | ms.assetid | caps.latest.revision | author | ms.author | manager | ||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Array.from Function (Array) (JavaScript) | Microsoft Docs |
01/18/2017 |
windows-client-threshold |
|
language-reference |
|
1bf59a99-f860-4c4d-b4c6-d5f1f946a490 |
3 |
mikejo5000 |
mikejo |
ghogen |
Returns an array from an array-like or iterable object.
Array.from (arrayLike [ , mapfn [ , thisArg ] ] );
arrayLike
Required. An array-like object or an iterable object.
mapfn
Optional. A mapping function to call on each element in arrayLike.
thisArg
Optional. Specifies the this object in the mapping function.
The arrayLike parameter must be either an object with indexed elements and a length property or an iterable object, such as a Set object.
The optional mapping function is called on each element in the array.
The following example returns an array from a collection of DOM element nodes.
var elemArr = Array.from(document.querySelectorAll('*'));
var elem = elemArr[0]; // elem contains a reference to the first DOM element
The following example returns an array of characters.
var charArr = Array.from("abc");
// charArr[0] == "a"; The following example returns an array of objects contained in the collection.
var setObj = new Set("a", "b", "c");
var objArr = Array.from(setObj);
// objArr[1] == "b"; The following example shows the use of arrow syntax and a mapping function to change the value of elements.
var arr = Array.from([1, 2, 3], x => x * 10);
// arr[0] == 10;
// arr[1] == 20;
// arr[2] == 30; [!INCLUDEjsv12]