O'Reilly logo

Learning ECMAScript 6 by Narayan Prusty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Arrays

ES6 adds new properties to the global Array object and to its instances to make working with arrays easier. Arrays in JavaScript lacked features and capabilities when compared with programming languages such as Python and Ruby therefore ES6 enhanced arrays to change that.

The Array.from(iterable, mapFunc, this) method

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 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:

letstr = "0123"; letobj = {number: 1}; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required