Skip to content

Instantly share code, notes, and snippets.

@sebdeckers
Created November 24, 2015 03:44
Show Gist options
  • Save sebdeckers/d66a84d275e46fce2567 to your computer and use it in GitHub Desktop.
Save sebdeckers/d66a84d275e46fce2567 to your computer and use it in GitHub Desktop.
Multiple values with `for ... of`
// Dummy data
var myMap = new Map();
myMap.set("0", "foo");
myMap.set(1, "bar");
myMap.set({}, "baz");
// entries() returns an array of arrays
for (const entry of myMap.entries(myMap))
console.log(entry)
// Console output:
// ["0","foo"]
// [1,"bar"]
// [{},"baz"]
// Protip: Destructure each `entry` array into its components
for (const [key, val] of myMap.entries(myMap))
console.log(key, val)
// Console output:
// 0 foo
// 1 bar
// {} baz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment