Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Set.prototype.has

Checks whether a value is in a Set.

Available since: ES2015

Syntax

set.has(value)

Parameters

ParameterTypeDescription
valueanyThe value to look for.

Return value

booleantrue if the value is in the Set.

Examples

Checking allowed values:

const allowed = new Set(['jpg', 'png', 'gif']);
 
console.log(allowed.has('png'));
console.log(allowed.has('exe'));

Output:

true
false

Notes

On large collections set.has() is much faster than array.includes(): it does not scan elements one by one.

See also

In the tutorial

  • Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.

Thanks for reading!

Donate to the site — we work hard for you.