JS: Set.prototype.add

By Xah Lee. Date: . Last updated: .

(new in JS: ECMAScript 2015)

mySet.add(value)
  • Add value to the set mySet.
  • Return the modified set.
// create a set, add value to it
const xx = new Set();
xx.add(6);
xx.add(5);
xx.add(6);

// the set is modified
console.log(xx);
// Set(2) { 6, 5 }

console.log(xx.add(7));
// Set(3) { 6, 5, 7 }

JS Set, Size Add Remove