Create an ES6 JavaScript Map

Link to stub:

Hint #1:
To create a Map object in JavaScript, you can do so by using the Map(); object constructor. To create a new Map object, you can use the new syntax.
Here’s how you would make a new Map and assign it to a variable:

let myVar = new Map();

Hint #2:
To add a key and value pair to the Map object, we can call the variable and use the .set(key, value) method.
Here’s how you would do it:

myVar.set('My Key', 'My Value');

OR you can just attach it to the Map() object like so:

let myVar = new Map().set('My Key', 'My Value');

Solution #1:

Create a variable that creates a new Map() object constructor. Then using the variable to chain the .set() method to assign a Key and Value to the Map() object.

let myMap = new Map();
myMap.set('freeCodeCamp', 'Awesome!');

Solution #2:

Creates a new Map() object and using the chaining method to chain the .set() to set the key and value of the Map() object.

let myMap = newMap().set('freeCodeCamp', 'Awesome!');

Heya stranger~!

A couple of proposed changes:

This should maybe be clarified to say "using the Map() constructor`.

Maybe instead of “sticks”, “uses method chaining”?

1 Like