ES6 - Collections Set Method add()


Advertisements

This method appends a new element with the given value to the Set object.

Syntax

mySet.add(value);

Parameters

  • Value − item to add to the list.

Return Value

Set Object.

Example

var set = new Set(); 
set.add(10); 
set.add(10); // duplicate not added 
set.add(10); // duplicate not added 
set.add(20); 
set.add(30); 
console.log(set.size);

Output

3
es6_collections.htm
Advertisements