Last Updated : 23 Jul, 2025
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:
Example 1: In this example, we have used sethas() method.
JavaScript
// Create a new set using Set() constructor
let myset = new Set();
// Append new elements to the
// set using add() method
myset.add(23);
myset.add(12);
// As 23 exists 23, it will return true
console.log(myset.has(23));
Example 2: In this example, we have used sethas() method.
JavaScript
// Create a new set using Set() constructor
let myset = new Set();
// Append new elements to the
// set using add() method
myset.add("Chicago");
myset.add("California");
myset.add("London");
// As London exists in the set,
// it will return true
console.log(myset.has("London"));
// As Manchester does not exist in the
// set, it will return false
console.log(myset.has("Manchester"));
Supported Browsers:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4