February 2018
Intermediate to advanced
298 pages
8h 22m
English
The Array.from() method creates a new array instance from an iterable object. The first argument is a reference to the iterable object. The second argument is optional and is a callback (known as the Map function) that is called for every element of the iterable object. The third argument is also optional and is the value of this inside the Map function.
Here is an example to demonstrate this:
let str = "0123";let arr = Array.from(str, value => parseInt(value) * 5);console.log(arr);
The output is:
[0, 5, 10, 15].
Array.from would be extremely useful in converting an "array-like" structure to the actual array. For example, when working with the Document Object Model (DOM) (discussed in Chapter ...
Read now
Unlock full access