Today, we’re going to look at the Map()
object.Let’s dig in.
Map()
objectThe 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