JS ES6 Two New DS


If you remember math from your school you may understand the purpose of the set in math if you do that’s right in JS Set has the ideal purpose as math does.

Some Useful Set Methods

Adding Items

we can add more items to a Set using add() method. this method adds a new value to the Set object and returns the Set. An attempt to add a duplicate value to the set object wouldn’t return an error,instead,the item will not be added.

Removing Item

we can remove more items from a Set object using delete() method. if the preferred item isn’t available in the Set returns false else return true.

Size of a Set

We can get the size of a Set using size() property on the Set prototype. This is similar to the length() property for Arrays.

Searching for items

We may need to know if a Set has a particular item. This can be accomplished using has() method. The has() method returns true if the item is in the Set object, and false if it isn’t.

Returning the Items in a Set

We can return the items in a Set object in the same insertion order using the values() method. This method returns a new setIterator object. A similar method for returning the items in a set using keys() method.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store



I am a web developer who writes web development content for you to make web development easier