JavaScript Code


JavaScript Set has()


Set has() method

has() method is used to check if the specified value is present in the set or not.

mySet.delete();
  • mySet is a set object.
  • has is method name.

The has() method returns a boolean value of true if the specified value is present, or false if the specified value is not present.

Examples

1. Check if the value 'e' is present in the vowels set.

const vowels = new Set(['a', 'e', 'i', 'o', 'u']);
if ( vowels.has('e') ) {
    console.log('value is present in set');
} else {
    console.log('value is not present in set');
}

Copyright @2022