Skip to content

Instantly share code, notes, and snippets.

@Sysetup
Created October 13, 2016 00:41
Show Gist options
  • Select an option

  • Save Sysetup/933eab9068cd1caed76d9f40f032503a to your computer and use it in GitHub Desktop.

Select an option

Save Sysetup/933eab9068cd1caed76d9f40f032503a to your computer and use it in GitHub Desktop.
Maps. Basic example.
var sayings = new Map();
sayings.set("dog", "woof");
sayings.set("cat", "meow");
sayings.set("elephant", "toot");
sayings.size; // 3
sayings.get("fox"); // undefined
sayings.has("bird"); // false
sayings.delete("dog");
sayings.has("dog"); // false
for (var [key, value] of sayings) {
console.log(key + " goes " + value);
}
// "cat goes meow"
// "elephant goes toot"
sayings.clear();
sayings.size; // 0
//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Keyed_collections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment