
ECMAScript 6 and new array functionalities
As you learned in Chapter 1, JavaScript – A Quick Overview, the JavaScript language has new functionalities according to the ECMAScript 2015 (ES6 or ES2015) and newer specifications (2015+).
The following is a list of the new methods added in ES2015 and ES2016:
Method |
Description |
@@iterator |
Returns an iterator object that contains the key/value pairs of the array that can be synchronously called to retrieve key/value of the array elements. |
copyWithin |
Copies a sequence of values of the array into the position of a start index. |
entries |
Returns @@iterator, which contains key/value pairs. |
includes |
Returns true if an element is found in the array, and false otherwise. This was added in ES2016. |
find |
Searches for an element in the array given the desired condition (callback function) and returns the element if it is found. |
findIndex |
Searches for an element in the array given the desired condition (callback function) and returns the element index if it is found. |
fill |
Fills the array with a static value. |
from |
Creates a new array from an existing one. |
keys |
Returns @@iterator, which contains the keys of the array. |
of |
Creates a new array from the arguments passed to the method. |
values |
Returns @@iterator, which contains the values of the array. |
Along with these methods, the Array API also provides a way of iterating the array which uses the Iterator object that can be retrieved from the array instance and used in the for...of loop.