Best way of creating 2D Javascript Array

Hello Experts,

Some advice needed please.

Currently, I am having a problem trying to create a 2D array.

My code is as follows:

1. marker is an array
2. Earlier in my code, I have declared:

var myArray = new Array();

var index1 = 123;
vat index 2 = 456;

Open in new window

Therefore, at the end of this procedure, I expect to be able to grab this marker using:


However the myArray[index1][index2].push(marker)

The error I get is:
"Error: 'myArray[...]' is null or not an object"

What am I doing wrong?
Is this the best way of assigning/retrieving data from a 2D array?

Who is Participating?
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.