GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — javascript-info/Set.md at master · stepanenko/javascript-info

Expand file tree

/

Set.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
33 lines (26 loc) · 1018 Bytes
/

Set.md

Copy path

File metadata and controls

33 lines (26 loc) · 1018 Bytes
Raw
Copy raw file
Download raw file
Edit and raw actions

Set

A Set object can be used to hold unique values (no repetitions are allowed). A value in a set can be anything (objects and primitive values).

The syntax new Set([iterable]) creates a Set object where iterable is an array or any other iterable object of values.

The size property returns the number of distinct values in a set.

For example:

let set = new Set([1, 2, 4, 2, 59, 9, 4, 9, 1]);
console.log(set.size); // 5

Methods:

  • add(value) Adds a new element with the given value to the Set.
  • delete(value) Deletes a specified value from the set.
  • has(value) Returns true if a specified value exists in the set and false otherwise.
  • clear() Clears the set.
  • values() Returns an Iterator of values in the set.

For example:

let set = new Set();

set.add(5).add(9).add(59).add(9);
console.log(set.has(9));

for (let v of set.values()) {
  console.log(v);
}

Set supports different data types i.e. 1 and "1" are two different values. NaN and undefined can also be stored in Set.

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.