UNB/ CS/ David Bremner/ teaching/ cs2613/ books/ mdn/ Reference/ Global Objects/ Set/ Set.prototype.add()

The add() method of Set instances inserts a new element with a specified value in to this set, if there isn't an element with the same value already in this set

Syntax

add(value)

Parameters

Return value

The Set object with added value.

Examples

Using the add() method

const mySet = new Set();

mySet.add(1);
mySet.add(5).add("some text"); // chainable

console.log(mySet);
// Set [1, 5, "some text"]

Specifications

Browser compatibility

See also