I have created a Map that has a string as key and an array of strings as value .
var miMapa = new Map();
miMapa.set("clave1", new Array("valor_a_1", "valor_a_2", "valor_a_3"));
miMapa.set("clave2", new Array("valor_b_1", "valor_b_2", "valor_b_3"));
miMapa.set("clave3", new Array("valor_c_1", "valor_c_2", "valor_c_3"));
I've tried looping through it like this: (i is fixed) (they share the same keys)
var keys = Object.keys(miMapa);
for (var n = 0; n < keys.length; n++) {
otroMapa.get(keys[n]).innerHTML = miMapa.get(keys[n])[i];
}
But it doesn't work. How do you loop through a Map in JavaScript, how do you get its key, and how do you get the value having its key?
If you look at the documentation
Map
Map Reference
you will see that you can perform a for
In your case
value
it is an array so you should do onefor
more to iterate through those values