DEV Community

Cover image for The Set() Object in JavaScript - A Nimble Introduction
RakibRahman
RakibRahman

Posted on

1 2

The Set() Object in JavaScript - A Nimble Introduction

Hello, I am going to give you a quick introduction about JavaScript Set() object and its must know properties and methods.

The Set() Object

The Set object is a collection of elements. It can store primitive values or object references.Set can only contains distinctive elements,so With Set object you can remove duplicate elements.


Using the Set object

  • Setting up an empty Set object empty set
  • Set object With array set with array

Iterating Sets

  • You can iterate over items in Set object using for...of statement. Iterating Sets

Adding an element to a set

  • You can add an element to the end of a Set object via the add() method. Alt Text

Number of elements in a Set

  • To see the number of (unique) elements in a Set object use the size property. size

Checking an element in the set

  • The has method will tell you whether a value exists in a Set object. has

Delete elements from set

  • Using delete method you can remove a value from the Set object. delete

Remove all elements from set

  • To remove all the elements from Set object simply use clear method. clear

Hope you have learnt something from this article.Kindly forgive any mistake as it is my first article. Happy Coding!

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay