Map Method in the Javascript
What is Map?
Map is the object in the JavaScript that holds the Key-value pairs and it can remember the original insertion order of the keys. In the Map, the value can hold both key and value.
Example :
const myMap = new Map();
myMap.set(0, "zero");
myMap.set(1, "one");
console.log(myMap.get('0'))
// Output : zero
There are some predefined methods in the maps are :
.clear()
.get()
.set()
.has()
.delete()
.forEach()
.size()
.values()
.keys()
.entries()
Iteration in Map
const map1 = new Map();
map1.set(0, "zero");
map1.set(1, "one");
for (const [key, value] of map1) {
console.log(`${key} = ${value}`);
}
// 0 = zero
// 1 = one
About the author
😇Don’t Be The Same, Be Better 👨🏻💻 #Python Programmer... 👨🏻💻 Full Stack Web Developer
Comments
Join the discussionNo comments yet. Be the first to comment.
