Set entries() method
entries()
method returns a new iterator object which contains an array of [value, value]
.
mySet.entries();
mySet
is a set object.entries
is method name.
entries()
method usually returns an iterator that contains an array of [key, value]
entries. Since an element in a set does not have a key, the key part of the entry is filled with the value itself.
Examples
1. Iterate over entries of the fruits
set.
const fruits = new Set(['apple', 'banana', 'cherry']);
for (const fruit of fruits.entries()) {
console.log(fruit);
}