The has method of the JavaScript Set determines if the Set object includes a given value. It yields true if the specified value exists within the Set; if not, it returns false.
Syntax
The has function is expressed using the subsequent syntax:
Example
setObj.has(value)
Parameter
value - It represents the value to be searched.
Return
A Boolean value.
JavaScript Set has method example
In this section, we will explore the has method by examining multiple examples.
Example 1
Let’s examine an example to verify if the set object includes the particular value in question.
Example
<script>
var set = new Set();
set.add("jQuery");
set.add("AngularJS");
set.add("Bootstrap");
document.writeln(set.has("Bootstrap"));
</script>
Output:
Example 2
Let us examine an additional example to ascertain if the set object includes the designated value.
Example
<script>
var set = new Set();
set.add("jQuery");
set.add("AngularJS");
set.add("Bootstrap");
document.writeln(set.has()+"<br>");
document.writeln(set.has(5));
</script>
Output:
Output
false
false