multidimensional array javascript

1

I have a following doubt. I will simplify as much as I can for you to understand. I am developing a game and I have an array with values. This array is multidimensional:

var valores = [["jaguatirica", "onça-pintada", "suçuarana"],["sabia","canario"],["pacu", "lambari"]]

And I have another multidimensional array with the image paths:

var img = [["jaguatirica.jpg", "onça-pintada.jpg", "suçuarana.jpg"],["sabia.jpg","canario.jpg"],["pacu.jpg", "lambari.jpg"]]

I want to turn these two arrays into one:

var resultado = [valores[0][0], img[0][0]]

which will result in: jaguatirica, jaguatirica.png.

But I want all values to come together with their respective images. Help me please, it's an educational game and will be used in municipal schools. developing game link

    
asked by anonymous 13.07.2016 / 16:06

1 answer

2

To merge all values and their respective images you have to go through each element of each array and pull to the array resultado .

var resultado = [];

for(var i = 0, ln = valores.length; i < ln; i ++) {
    for(var b = 0, len = valores[i].length; b < len; b ++) {
        resultado.push([
            valores[i][b],
            img[i][b]
        ]);
    }
}
    
13.07.2016 / 16:17