How to Check if a Specific Element Exists in a Set in JavaScript ? Last Updated : 30 Jan, 2024 Comments Improve Suggest changes Like Article Like Report To check if a specific element exists in a Set in JavaScript, you can use the has method. The has method returns a boolean indicating whether an element with the specified value exists in the 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: Here, we have checked whether "yellow" exists in tempset or not, as it is present we got the output as true. The has( ) method takes one value as a parameter and checks whether it is present in the set given or not. JavaScript let tempset =new Set(); tempset.add("red"); tempset.add("green"); tempset.add("blue"); tempset.add("yellow"); tempset.add("digitalvasanth"); console.log(tempset.has("yellow")); Outputtrue Example 2: Here, we have passed 99 to has( ) , which is not present in tempset, so it returned false as output. JavaScript let tempset =new Set(); tempset.add(80); tempset.add(88); tempset.add(90); tempset.add(77); console.log(tempset.has(99)); Outputfalse Comment More infoAdvertise with us Next Article How to Check if a Specific Element Exists in a Set in JavaScript ? D digitalvasanth Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League Geeks Premier League 2023 Similar Reads How to Check if an Element Exists in an Array in JavaScript? Given an array, the task is to check whether an element present in an array or not in JavaScript. If the element present in array, then it returns true, otherwise returns false.The indexOf() method returns the index of first occurance of element in an array, and -1 of the element not found in array. 2 min read How to Check an Element with Specific ID Exists using JavaScript ? Given an HTML document containing some elements and the elements contain some id attribute. The task is to check whether the element with a specific ID exists or not using JavaScript. Below are the approaches to check an element with specific ID exists or not using JavaScript:Â Table of ContentApproa 3 min read How to Check if element exists in the visible DOM in JavaScript ? This article will show you how to check whether an element exists in the visible DOM or not. For that purpose, there are several methods used but we're going to look at a few of them. Example 1: In this example, the element is searched by document.getElementById('Id') and !! operator is used before 2 min read How to Check if an Object has a Specific Property in JavaScript ? In JavaScript, objects can have properties that store data or functions. Sometimes it is necessary to check whether an object has a specific property. This can be useful, for example, when you want to avoid calling a function on an object that doesn't have that function defined as a property. In thi 3 min read How to Check a Key Exists in JavaScript Object? Here are different ways to check a key exists in an object in JavaScript.Note: Objects in JavaScript are non-primitive data types that hold an unordered collection of key-value pairs. check a key exists in JavaScript object1. Using in Operator The in operator in JavaScript checks if a key exists in 2 min read Like