JavaScript Set Object



new Set([iterable])


iterable - It represents an iterable object whose elements will be added to the new Set.

Points to remember

  • A set object uses the concept of keys internally.
  • A set object cannot contain the duplicate values.
  • A set object iterates its elements in insertion order.

JavaScript Set Methods

Let's see the list of JavaScript set methods with their description.

add()It adds the specified values to the Set object.
clear()It removes all the elements from the Set object.
delete()It deletes the specified element from the Set object.
entries()It returns an object of Set iterator that contains an array of [value, value] for each element.
forEach()It executes the specified function once for each value.
has()It indicates whether the Set object contains the specified value element.
values()It returns an object of Set iterator that contains the values for each element.