Languages
[Edit]
EN

JavaScript - print Set items

3 points
Created by:
ArcadeParade
666

In this article, we would like to show you how to print Set items in JavaScript.

Quick solution:

// ONLINE-RUNNER:browser;

const collection = new Set();

collection.add('1');
collection.add('2');
collection.add('3');

console.log(...collection);

 

Other solutions

In this section, we iterate through Set to print set items in the console.

Example 1:

// ONLINE-RUNNER:browser;

const collection = new Set();

collection.add('1');
collection.add('2');
collection.add('3');

for (const item of collection) {
    console.log(item);
}

Example 2:

// ONLINE-RUNNER:browser;

const collection = new Set();

collection.add('1');
collection.add('2');
collection.add('3');

for (const [key, value] of collection.entries()) {
    console.log(value);
}

 

See also

Alternative titles

  1. JavaScript - print set in the console
  2. JavaScript - console.log set
  3. JavaScript - display set in the console
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join