bhylu.com

Advertisements

JS Map Reference

Maps are iterable in insertion order. Destructure each entry into a key and value when looping.

Where to run this

This example uses the JavaScript console playground. Select Run to execute it; the example does not run on this lesson page.

A practical example

JavaScript

const stock = new Map([["tape", 3], ["glue", 5]]);
for (const [item, count] of stock) {
  console.log(item + ": " + count);
}

What happens

Each key is printed beside its count.