---
title: "How to create a new Set in JavaScrip?"  
description: "How to create a new Set in JavaScrip?"  
author: "Steilla Mitchel"  
published: 2023-10-30  
updated: 2023-10-31  
canonical: https://www.mindstick.com/forum/160319/how-to-create-a-new-set-in-javascrip  
category: "javascript"  
tags: ["javascript", "javascript object", "functions"]  
reading_time: 1 minute  

---

# How to create a new Set in JavaScrip?

How to create a new Set in JavaScrip?

## Replies

### Reply by Aryan Kumar

You can create a new Set in JavaScript using the **Set** constructor. Here's how you can do it:

```plaintext
const mySet = new Set();
```

In the above code, **mySet** is a new Set that is initially empty. You can also create a Set with an iterable, such as an array or another Set, by passing it as an argument to the **Set** constructor. For example:

```plaintext
const mySet = new Set([1, 2, 3, 4]);
```

This creates a new Set called **mySet** with the elements 1, 2, 3, and 4. The Set will automatically eliminate any duplicate values, so you'll end up with a Set containing unique elements.

You can also add elements to the Set later using the **add** method:

```plaintext
mySet.add(5);
mySet.add(6);
```

Now, **mySet** contains the elements 1, 2, 3, 4, 5, and 6.

Sets in JavaScript are a useful data structure for maintaining collections of unique values, and they provide various methods for adding, removing, and checking the existence of elements.


---

Original Source: https://www.mindstick.com/forum/160319/how-to-create-a-new-set-in-javascrip

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
