for loop over array in a array in javascript

To loop over an array in a nested array in JavaScript, you can use a for loop nested inside another for loop. Here's an example:

index.tsx
const nestedArray = [[1, 2, 3], [4, 5, 6], [7, 8, 9]];

for(let i = 0; i < nestedArray.length; i++) {
  for(let j = 0; j < nestedArray[i].length; j++) {
    console.log(nestedArray[i][j]);
  }
}
195 chars
8 lines

In this example, we have a nestedArray that contains three arrays. The outer loop iterates over each array in the nestedArray, and the inner loop iterates over each element in the current array. The console.log statement inside the inner loop outputs each element to the console.

You can modify the code inside the nested loop to perform any operation on the elements of the nested array.

gistlibby LogSnag