Today, we’re going to look at the Map() object.Let’s dig in.

What is the Map() object

The Map() object is to plain objects ({}) what Set() is to arrays.

A Map() object is an iterable of key/value pairs that are stored and looped through in order. The big difference between a Map() and a plain object is that Map() items retain their order, while plain object values do not.

You can create a Map() object with the new Map() constructor. Pass in an iterable of key value pairs (also as an iterable such as an array) as an argument.

// returns Map(2) {"name" => "Radagast", "color" => "brown"}
let radagast = new Map([
	['name', 'Radagast'],
	['color', 'brown']
]);

#javascript #programming #web-development #developer

How to use the Map() Object in Vanilla JavaScript
2.05 GEEK