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:
xxxxxxxxxx
1
const collection = new Set();
2
3
collection.add('1');
4
collection.add('2');
5
collection.add('3');
6
7
console.log(collection);
In this section, we iterate through Set
to print set items in the console.
Example 1:
xxxxxxxxxx
1
const collection = new Set();
2
3
collection.add('1');
4
collection.add('2');
5
collection.add('3');
6
7
for (const item of collection) {
8
console.log(item);
9
}
Example 2:
xxxxxxxxxx
1
const collection = new Set();
2
3
collection.add('1');
4
collection.add('2');
5
collection.add('3');
6
7
for (const [key, value] of collection.entries()) {
8
console.log(value);
9
}