bhylu.com

Advertisements

JS Set Methods

Use add, has, and delete to manage membership. Size reports how many distinct entries remain.

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 attendees = new Set();
attendees.add("Mira");
attendees.add("Jon");
attendees.delete("Jon");
console.log(attendees.has("Mira"), attendees.size);

What happens

Mira is present and the size is 1.