Set method in JavaScript

Set method in JavaScript

Hello readers!

I have been here after a long time.Today,I have come up with a fresh and interesting topic of the JavaScript.Before going on the topic ,let's talk about JavaScript first.In today world , JavaScript is growing with rapid speed.In almost every field, JavaScript is being used.JavaScript is a complete programming language .It is used in the front-end,back-end and database.Javascript is useful for us in many ways.Nowadays,It is used in making mobile apps.Actually,HTML ,CSS and JavaScript are core part of any website front-end.Javascript provides functionality to the webpages like button click,zooming and lookout etc.

We have talked a lot about JavaScript.So , let's come to the topic and dive into it.As we know, JavaScript has built-in method and Set is one of them.

"A set is a method which stores unique value of any type such as numbers,string etc. For example,here are a list of cartoon characters which is my favourite personally. {"Nobita","Doreman","Tom","Jerry","Suzuka","Chhota Bhim"}. Here is no repetition.If you are trying to repeat the value,only one value exist in the set.Please let me know your favourite anime or cartoon characters.

There are many properties of set which we will study today. 1. new keyword to create new Set. 2.Set.add() to add value in the set. 3. Set.clear() to remove all value in the set. 4. Set.size to know the size of the set. 5. Set.has() to ask question whether the value present or not. 6. Set.delete() to delete the element of the given value in the set. 7.Set.enteries() to get key-value pairs in the set. 8.Set.keys() to get key of the set. 9.Set.values() to get value of the set. 10.Set.forEach() to iterate over the set.

Here is the code for the set:

// Create a set. const mySet = new Set();

// Add elements to the set mySet.add('apple'); mySet.add('banana'); mySet.add('cherry');

// Get the size of the set console.log(mySet.size); // Output: 3

// Check if an element is in the set console.log(mySet.has('banana')); // Output: true

// Delete an element from the set mySet.delete('cherry');

// Loop through the set mySet.forEach(element => { console.log(element); });

// Output: apple banana

// Convert set to an array const myArray = Array.from(mySet); console.log(myArray); // Output: ["apple", "banana"]

So ,you can known about set in detail on the men.So for today,that is it.Goodnight!