Javascript Map and Set
Map is a collection of key associated data, where key can be of any type. It can be of integer, can be of string etc.
It is similar to object but only difference is that, it allowed to have a key of any data type.
Example:
let map = new Map();
map.set("name", "Avinash");
map.set(1, "one");
map.set(true, "active")
We can access then the map data
console.log(map.get("name")) //"Avinash"
console.log(map.get(1)) //"one"
console.log(map.get(true)) //"active"
Set is a collection of data without any association of keys. And the value in the Set always be an unique.
Example:
let set = new Set(["Avinash", "Kumar", "Avinash"]);
console.log(set) // ["Avinash", "Kumar"]

0 Comments