Javatpoint Logo
Javatpoint Logo

JavaScript Set Object

The JavaScript Set object is used to store the elements with unique values. The values can be of any type i.e. whether primitive values or object references.

Syntax

Parameter

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.

Methods 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.





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA