Learn how to use the Map() object in vanilla JavaScript. 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. 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.
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']
]);
With the rapid development in technology, the old ways to do business have changed completely. A lot more advanced and developed ways are ...
You name the business and I will tell you how web development can help you promote your business. If it is a startup or you seeking some...
We are the best offshore web development company in India providing web applications on Blockchain, AI & Chatbots. 15+ Yrs Exp., Save upto 60% on development.
Hire Dedicated JavaScript Developers from a top javascript development agency for your business solutions. We provide JS web developers for hire at a fixed or hourly rate.
JavaScript values are allocated when things are created (objects, Strings, etc.) and freed automatically when they are no longer used. This process is called Garbage collection.