JavaScript Set Has Method Checking If The Set Has The Specified Element

Checking if the set has the specified element (has method)

If we are required to check, whether or not the specified element is there in the set, or we can say it in another way, that whether or not our set HAS this specified element, we can simply make use of the has method.

JavaScript Set Has

So, simply speaking, the has method is going to determine whether or not, the set contains the specified element, and if the set contains the specified element, the has method returns true, or else it returns false. Let’s have a look at an example, which demonstrates the same thing –

You might have guessed the output here. We are just checking whether or not someSet has 5, and then we are again asking whether someSet has 100? Well, the method is going to return either true or false. In the first case, the output is going to be true, since 5 is there in the set. In the second case, the output is going to be false, since 100 is not there in the set. This is pretty simple and straightforward, and you can use this method to test whether or not something is there in the set or not.