EN
JavaScript - print Set items
3
points
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);
}