Link to stub:
https://forum.freecodecamp.org/t/freecodecamp-challenge-guide-create-an-es6-javascript-map/301635/2
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');
Solutions
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!');