Open In App

Javascript Set Programming Examples

Last Updated : 01 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In JavaScript, the Set object is a built-in collection that allows you to store unique values of any type, Set can store any type of value whether primitive or objects. It provides methods for adding, removing, and querying elements in an efficient way.

Syntax:

new Set([iterable]);

Parameter:

  • iterable: It represents an iterable object whose all elements are added to the new set created, If the parameter is not specified or null is passed then a new set created is empty.

Example: Here is the basic example of a Javascript set.

Javascript




let name = new Set(["GeeksforGeeks"]);
console.log(name);


Output:

Set(1) {'GeeksforGeeks'}

The following JavaScript section contains a wide collection of JavaScript Set examples. Many of these programming examples contain multiple approaches to solving the problem.

  1. How to iterate over Set elements in JavaScript?
  2. How to get the union of two sets in JavaScript?
  3. How are elements ordered in a Set in JavaScript?
  4. How to sort a set in JavaScript?
  5. How to Convert Array to Set in JavaScript?
  6. How to map, reduce and filter a Set element using JavaScript ?
  7. Difference between Set.clear() and Set.delete() Methods in JavaScript
  8. Set vs Map in JavaScript
  9. How to perform intersection of two sets in JavaScript?
  10. Get the Difference between Two Sets using JavaScript

We have a complete list of Javascript Set Programming Examples, to check those please go through this JavaScript Set Complete Reference article.

We have created a complete JavaScript Tutorial to help both beginners and experienced professionals. Please check this JavaScript Tutorial to get the complete content from basic syntax and data types to advanced topics such as object-oriented programming and DOM manipulation.

We have created an article on JavaScript Examples and added a list of questions based on Array, Object, Function, …, etc. Please visit this JavaScript Examples to get a complete questions-based articles list of JavaScript.

Recent articles on Javascript


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads