Map in JavaScript, go through, get keys and values

2

I have created a Map that has clave as a string and as value a arrays of strings .

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 tried to go 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 does not work. How do you run a Map in JavaScript, how do you get your key and how do you get the value with your password?

    
asked by dddenis 10.02.2016 в 11:53
source

1 answer

3

If you analyze the documentation of Map

Map Reference

You'll see that you can make a for

for (var [key, value] of miMapa) {
  alert(key + " = " + value);
}

In your case the value is an array so you should do for more to iterate through those values

    
answered by 10.02.2016 / 12:50
source