Skip to content

Instantly share code, notes, and snippets.

@Hacking-NASSA-with-HTML
Created December 17, 2022 21:36
Show Gist options
  • Save Hacking-NASSA-with-HTML/b4d856008fceb75061d364fbb54fd47c to your computer and use it in GitHub Desktop.
Save Hacking-NASSA-with-HTML/b4d856008fceb75061d364fbb54fd47c to your computer and use it in GitHub Desktop.
Using array destructuring, fix the following code to print the keys and values of the `members` Map
// Using array destructuring, fix the following code to print the keys and values of the `members` Map to the console.
const members = new Map()
members.set('Evelyn', 75.68)
members.set('Liam', 20.16)
members.set('Sophia', 0)
members.set('Marcus', 10.25)
let key
let value
for (const member of members) {
[key, value] = member
console.log(key, value)
}
// The second variant
const members = new Map()
members.set('Evelyn', 75.68)
members.set('Liam', 20.16)
members.set('Sophia', 0)
members.set('Marcus', 10.25)
let key
let value
members.forEach((value, key) => console.log(key, value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment