'How to loop through and reference with an array in an array?

I have this array and it has an array with different number of elements.

var filtered = [Array(3), Array(1), Array(2), Array(7), Array(1), Array(1), Array(5)]

0: Array(3)

    0: {fixture: {…}, league: {…}, teams: {…}, goals: {…}, score: {…}}

    1: {fixture: {…}, league: {…}, teams: {…}, goals: {…}, score: {…}}

    2: {fixture: {…}, league: {…}, teams: {…}, goals: {…}, score: {…}}


1: [{…}]                         //1 element

2: (2) [{…}, {…}]                //2 elements

3: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]             //7 elements

I want to access the data inside through looping so I try to use this:

for (i = 0; i < filtered.length-1; i++) {

   for (x=0; x<filtered[i].length-1;x++){

    let league = document.createElement("div")
    league.className = 'league'
    league.innerHTML = filtered[i].x.league.name                //error occurs on .league.name
    parent.appendChild(league)

}}

and I get this error message:

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'league')

I likely am referencing it wrong but do not know how else to do this.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source