11New Array Features, Typed Arrays

In this chapter, you'll learn about many new features of arrays in ES2015+, including new features for traditional arrays and the new typed arrays.

Before getting into the meat of the chapter, a brief note about terminology: There are a couple of words used to refer to the contents of arrays, the two most popular being “elements” and “entries.” Although “elements” is probably used slightly more often than “entries,” I use “entries” in this book to avoid confusion with DOM elements and because it's the name of the method on arrays, entries, that you use to get an iterator for the entries in the array. But you'll very often hear “elements” instead, including in most parts of the JavaScript specification. “Element” is also used in one place in the standard API for typed arrays.

NEW ARRAY METHODS

ES2015 (primarily), ES2016, and ES2019 added a host of new array methods, both for creating arrays and for accessing and modifying their contents.

Array.of

Signature:

arrayObject = Array.of(value0[, value1[, … ]])

Array.of creates and returns an array containing the values you pass to it as discrete arguments. For instance:

const a = Array.of("one", "two", "three");
console.log(a); // ["one", "two", ...

Get JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.