1
I printed it manually and then tried using a for
to carry out the printing, but I happen not to be able to display it properly.
let mochila = new Array();
let item1 = ['corda', 2],
item2 = ['faca', 3],
item3 = ['cura', 23],
item4 = ['prego', 35];
mochila.push(item1);
mochila.push(item2);
mochila.push(item3);
mochila.push(item4);
document.write(mochila[0][0] + ' - ' + mochila[0][1] + '<br/>');
document.write(mochila[1][0] + ' - ' + mochila[1][1] + '<br/>');
document.write(mochila[2][0] + ' - ' + mochila[2][1] + '<br/>');
document.write(mochila[3][0] + ' - ' + mochila[3][1] + '<br/>');
document.write('----------------------------------------<br/>');
for(let i = 0; i < item1.length; i++){
for(let j = 0; j < item1.length; j++){
document.write(mochila[i][j] + ' - ' + mochila[i][j] + '<br/>');
}
}
Shouldn’t be
i < mochila.length
?– bfavaretto
It is also interesting to note that the
push
supports multiple elements. So could domochila.push(item1, item2, item3, item4);
– Isac
Even the
push
supporting multiple elements is interesting to note that the entire matrix could be created using array literals– fernandosavio
I gave it a neat one in the code, but I don’t know how to use it. I put itens1.length for me to carry out the 4 impressions, so at the time I use and j to print the matrix it ends up leaving in a wrong way.
– Erick Ferrara Bazan
Already followed @bfavaretto’s tip ? Your first limit
for
is wrong and should be adjusted to what has been indicated– Isac
I’ve tried, she actually duplicates the print, displaying more than she should, just the wrong way.
– Erick Ferrara Bazan
Got it, thanks for your help, guys.
– Erick Ferrara Bazan