JavaScript Set has()

Definition and usage

has() The method is used to check if a specified value exists in the Set, and returns true if it does.

Instance

// Create a Set
const letters = new Set(["a", "b", "c"]);
// Check if the Set contains "d"?
answer = letters.has("d");

Try it yourself

Syntax

set.has(value)

Parameter

Parameter Description
value Required. The value to be checked.

Return value

Type Description
Boolean Returns true if the value exists; otherwise returns false.

Browser support

set.has() Is a feature of ECMAScript6 (ES6).

Since June 2017, all modern browsers support ES6 (JavaScript 2015):

Chrome Edge Firefox Safari Opera
Chrome 51 Edge 15 Firefox 54 Safari 10 Opera 38
May 2016 April 2017 June 2017 September 2016 June 2016

Internet Explorer Does Not Support set.has().

Related Pages: JavaScript Sets JavaScript Iterables Full JavaScript Set Reference