loading
open in
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// Empty map
let stuff = new Map();

// Add elements to Map
stuff.set('vowels',['a','e','i','o','u']);
stuff.set('numbers', [1,2,3,4,5]);
stuff.set('pi','3.14159265359');

// Loop over Map
stuff.forEach(function(value, key) {
  console.log(key + ' = ' + value);
});

// Get specific Map value
console.log(stuff.get('numbers'));

// Get an array with keys in Map
console.log(Array.from(stuff.keys()));

// Get an array with values in Map
console.log(Array.from(stuff.values()));

// Populate Map on creation 
let languageCreators = new Map([['JavaScript', 'Brendan Eich'], ['Python', 'Guido van Rossum']]);

console.log("JavaScript was created by " + languageCreators.get('JavaScript'));
console.log("Python was created by " + languageCreators.get('Python'));
Native Browser JavaScript