JavaScript Code

JavaScript Set entries()


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);
}

Copyright @2022