Creating an array of arrays filled with 'false'

I am trying to create an array of arrays which are all filled with false in JavaScript. However, I keep getting this error:

Uncaught TypeError: Cannot read property 'push' of undefined

My current code is this:

var fieldFilled = [];

for (var i = 0; i < 10; i++) {
    fieldFilled.push([]);
            
    for (var j = 0; j < 10; j++) {
        fieldFilled[j].push(false);
    }
}

I don’t understand this error because it seems like fieldFilled is defined.

Thank you for your help.

1 thought on “Creating an array of arrays filled with 'false'”

Leave a Comment