forEach in array array does not work

0

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?

    
asked by hubman 07.12.2016 в 17:53
source

1 answer

1

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);
    });
});
    
answered by 07.12.2016 / 18:01
source