[JavaScript] forEach with Maps and Sets
![[JavaScript] forEach with Maps and Sets](https://cdn.hashnode.com/res/hashnode/image/unsplash/ZS67i1HLllo/upload/v1655999747161/5Ju2EeZhuR.jpeg)
// Maps
const currencies = new Map([
['USD', 'United States dollar'],
['EUR', 'Euro'],
['GBP', 'Pound sterling'],
]);
currencies.forEach(function (value, key, map) {
console.log(`${key}: ${value}`);
});
//Sets
const currenciesUnique = new Set(['USD', 'GBP', 'USD', 'EUR', 'EUR']);
console.log(currenciesUnique);
currenciesUnique.forEach(function (value, _, map) {
console.log(`${value}: ${value}`);
});
Set does not have any key or index here.