my code is as follows
var array=[[1,2,3],[4,5,6],[7,8,9]];
array.forEach(function(indice){
array[indice].forEach(function(index){
console.log(array[indice][index]);
})
})
does not work, why?
my code is as follows
var array=[[1,2,3],[4,5,6],[7,8,9]];
array.forEach(function(indice){
array[indice].forEach(function(index){
console.log(array[indice][index]);
})
})
does not work, why?
The forEach()
method sends as a parameter to the function, the content of the relevant position of the matrix, not the index.
What you are looking for looks like this:
var array=[[1,2,3],[4,5,6],[7,8,9]];
array.forEach(function(indice){
indice.forEach(function(index){
console.log(index);
});
});