bhylu.com

Advertisements

JS Map Methods

Has distinguishes a missing key from a key whose value is undefined. Delete removes an entry.

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", 0]]);
console.log(stock.has("glue"));
stock.delete("tape");
console.log(stock.size);

What happens

Glue exists even though its count is zero; one entry remains.