# Iterating over multidimensional structures in JavaScript

Let we have the following object with students:

`let students = { 'group1': ['student11', 'student12', 'student13'], 'group2': ['student21', 'student22', 'student23'], 'group3': ['student31', 'student32'], };`

Let's display the names of all the students by looping through our object in two nested loops.

As you can see, we have an object with arrays. This means that the first loop should be for an object, and the second loop should be for arrays. That is, the first loop will be `for-in`, and the second - `for-of`, like this:

`for (let group in students) { for (let name of students[group]) { console.log(name); } }`

Given the following data structure:

`let data = { 1: [ 'data11', 'data12', 'data13', ], 2: [ 'data21', 'data22', 'data23', ], 3: [ 'data31', 'data32', 'data33', ], 4: [ 'data41', 'data42', 'data43', ], };`

Use nested loops to display all data strings.

Given the following data structure:

`let data = [ { 1: 'data11', 2: 'data12', 3: 'data13', }, { 1: 'data21', 2: 'data22', 3: 'data33', }, { 1: 'data31', 2: 'data32', 3: 'data33', }, ];`

Use nested loops to display all data strings.

Given the following data structure:

`let data = [ { 1: [ 'data111', 'data112', 'data113', ], 2: [ 'data121', 'data122', 'data123', ], }, { 1: [ 'data211', 'data212', 'data213', ], 2: [ 'data221', 'data222', 'data223', ], }, { 1: [ 'data411', 'data412', 'data413', ], 2: [ 'data421', 'data422', 'data423', ], }, ];`

Use nested loops to display all data strings.

←→
↑
en ru