JavaScript Set has() Method - JavaScript Tutorial

JavaScript Set has() Method

BLUF: This tutorial on JavaScript Set has() Method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Set has() Method

Understanding JavaScript Set has() Method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

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

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience