Reader small image

You're reading from  Professional JavaScript for Web Developers - Fourth Edition

Product typeBook
Published inNov 2019
Reading LevelBeginner
PublisherWiley
ISBN-139781119366447
Edition4th Edition
Languages
Right arrow
Author (1)
Matt Frisbie
Matt Frisbie
author image
Matt Frisbie

Matt Frisbie has worked in web development for over a decade. During that time, he's been a startup co-founder, an engineer at a Big Four tech company, and the first engineer at a Y Combinator startup that would eventually become a billion-dollar company. As a Google software engineer, Matt worked on both the AdSense and Accelerated Mobile Pages (AMP) platforms; his code contributions run on most of the planet's web browsing devices. Prior to this, Matt was the first engineer at DoorDash, where he helped lay the foundation for a company that has become the leader in online food delivery. Matt has written two books and recorded two video series for O'Reilly and Packt, speaks at frontend meetups and web casts, and is a level 1 sommelier. He majored in Computer Engineering at the University of Illinois Urbana-Champaign. Matt's Twitter handle is @mattfriz.
Read more about Matt Frisbie

Right arrow

ITERATION AND SPREAD OPERATORS

ECMAScript 6 introduced iterators and the spread operator, which are especially useful in the context of collection reference types. These new tools allow for easy interoperability, cloning, and modification of collection types.

As shown earlier in the chapter, four native collection reference types define a default iterator:

  • Array
  • All typed arrays
  • Map
  • Set

Trivially, this means that all support ordered iteration and can be passed to a for..of loop:

let iterableThings = [
 Array.of(1, 2),
 typedArr = Int16Array.of(3, 4),
 new Map([[5, 6], [7, 8]]),
 new Set([9, 10])
];
  

for (const iterableThing of iterableThings) {
 for (const x of iterableThing) {
  console.log(x);
 }
}

// 1
// 2
// 3
// 4
// [5, 6]
// [7, 8]
// 9
// 10

This also means that all these types are compatible with the spread operator. The spread operator is especially...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Professional JavaScript for Web Developers - Fourth Edition
Published in: Nov 2019Publisher: WileyISBN-13: 9781119366447

Author (1)

author image
Matt Frisbie

Matt Frisbie has worked in web development for over a decade. During that time, he's been a startup co-founder, an engineer at a Big Four tech company, and the first engineer at a Y Combinator startup that would eventually become a billion-dollar company. As a Google software engineer, Matt worked on both the AdSense and Accelerated Mobile Pages (AMP) platforms; his code contributions run on most of the planet's web browsing devices. Prior to this, Matt was the first engineer at DoorDash, where he helped lay the foundation for a company that has become the leader in online food delivery. Matt has written two books and recorded two video series for O'Reilly and Packt, speaks at frontend meetups and web casts, and is a level 1 sommelier. He majored in Computer Engineering at the University of Illinois Urbana-Champaign. Matt's Twitter handle is @mattfriz.
Read more about Matt Frisbie