How can I create a two dimensional array in JavaScript?

后端 未结 30 4347
天涯浪人
天涯浪人 2020-11-21 05:25

I have been reading online and some places say it isn\'t possible, some say it is and then give an example and others refute the example, etc.

  1. How do I dec

30条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-21 05:48

    You simply make each item within the array an array.

    var x = new Array(10);
    
    for (var i = 0; i < x.length; i++) {
      x[i] = new Array(3);
    }
    
    console.log(x);

提交回复
热议问题