JavaScript set entries method returns an iterator object which holds the contents of the current Set. This object contains an array of [value, value] for each element. It maintains insertion order.
setObj.entries()
JavaScript set entries
Simple example code to understand entries() method.
<!DOCTYPE html>
<html>
<body>
<script>
const set1 = new Set();
set1.add(100);
set1.add('ABC');
const iterator1 = set1.entries();
for (const entry of iterator1) {
console.log(entry);
}
</script>
</body>
</html>
Output:
More examples
const mySet = new Set();
mySet.add('foobar');
mySet.add(1);
mySet.add('baz');
const setIter = mySet.entries();
console.log(setIter.next().value); // ["foobar", "foobar"]
console.log(setIter.next().value); // [1, 1]
console.log(setIter.next().value); // ["baz", "baz"]
Do comment if you have any doubts or suggestions on this Js set method topic.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version