JavaScript: Set Object

By Xah Lee. Date: . Last updated: .

New in JS2015.

See also: the Set Object Tutorial

Set is the value of the property key "Set" of the Global Object .

console.log( window.Set === Set ); // true

Type

Type of Set is a function.

console.log( typeof Set === "function" ); // true

Parent

Parent of Set is Function.prototype. [see Prototype and Inheritance]

console.log( Reflect.getPrototypeOf ( Set ) === Function.prototype ); // true

Purpose

Purpose of Set is:

“Set” objects are collections of values.

[see the Set Object Tutorial]

How Set Determines Uniqueness

The equality test used for determining whether 2 values in a set is the same as ===, except treatment of NaN (not a number).

NaN === NaN return false, but for set object, NaN is considered same as any NaN.

// equality test used for determining whether 2 values in the set is the same as ===, except treatment of NaN

// this is false
console.log(NaN === NaN); // false

// but for set object, NaN is same as any NaN
const s = new Set([NaN, NaN]);
console.log(s); // Set { NaN }

Set Constructor

Set Constructor

Properties

JavaScript Set Object

JS in Depth
XAH  BUY NOW

JS in Depth

JS Obj Ref

DOM


JS Obj Ref

Set

prototype