JavaScript Set has() Method
Last Updated :
15 Dec, 2023
The Set.has() method in JavaScript is used to check whether an element with a specified value exists in a Set or not. It returns a boolean value indicating the presence or absence of an element with a specified value in a Set.
Syntax:
mySet.has(value);
Parameters:
- value: It is the value of the element that has to be checked if it exists in the Set.
Example 1: In this example, we have used sethas() method.
Javascript
let myset = new Set();
myset.add(23);
myset.add(12);
console.log(myset.has(23));
|
Example 2: In this example, we have used sethas() method.
Javascript
let myset = new Set();
myset.add( "Chicago" );
myset.add( "California" );
myset.add( "London" );
console.log(myset.has( "London" ));
console.log(myset.has( "Manchester" ));
|
We have a complete list of Javascript Set methods, to check those please go through this Sets in JavaScript article.
We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.
Share your thoughts in the comments
Please Login to comment...