Javascript - Map Data Type

About

Type

Object

Object as associative array.

let a = { "a":1, "b":1 };
a["b"]=2;
console.log(a);

Map

A map object has also been create to implement a more sophisticated map type.

Example:

keyValues= new Map();
keyValues.set("name","nico");
keyValues.set("color","blue");
for (const keyValue of keyValues){
    const [key, value] = keyValue 
    console.log("Key: "+key+", value: "+value);
}

values return an iterator

keyValues= new Map();
keyValues.set("name","nico");
keyValues.set("color","blue");

it = keyValues.values();
let result = it.next();
while (!result.done) {
 console.log(result.value); 
 result = it.next();
}

Documentation / Reference


Powered by ComboStrap