Javascript Maps

JavaScript Maps

ES6 now offers Maps, another list type that offers an infrastructure to manage collections of data with name/value pairs.

USAGE: Copy and paste the code samples below into the Javascript console in your browser, then simply hit return on your keyboard to see the code in action.

//Maps
let card_ace = {
  name: "Ace of Spades"
};
let card_king = {
  name: "King of Clubs"
};

let deck = new Map();
deck.set("as", card_ace);
deck.set("kc", card_king);

console.log(deck);
//deck.size; deck.get('kc'); deck.delete('as'); deck.clear(); deck.keys()

for (key of deck.keys()) {
  console.log(key);
}

for (value of deck.values()) {
  console.log(value);
}

for (entry of deck.entries()) {
  console.log(entry);
}


Link your website to this page! Copy and paste the URL below:
http://www.cfsnap.com/javascript/javascript-maps/
Copyright 2019. All Rights Reserved.