0

How to create an empty 2d array in javascript? below is an example of what I want to create

[[1, a, c], [2, d, e], [3, w, e]];

I just want to create a empty 2d array. Note I dont know any of the values and I dont know the size of array:

var a= [][] ??

0

3 Answers 3

1

This should work:

var a = [[], [], []];
Sign up to request clarification or add additional context in comments.

Comments

0

The following code should create a new array, and then push three elements that make up a similar content of what you requested (string values instead of variables).

var a = [];
a.push([1, 'a', 'c']);
a.push([2, 'd', 'e']);
a.push([3, 'w', 'e']);

Comments

0

Well, if you want to create a new, completely blank, 2D Array:

var array = [[]];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.