How can I create a two dimensional array in JavaScript?

后端 未结 30 4283
天涯浪人
天涯浪人 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:36

    The easiest way:

    var arr  = [];
    
    var arr1 = ['00','01'];
    var arr2 = ['10','11'];
    var arr3 = ['20','21'];
    
    arr.push(arr1);
    arr.push(arr2);
    arr.push(arr3);
    
    alert(arr[0][1]); // '01'
    alert(arr[1][1]); // '11'
    alert(arr[2][0]); // '20'
    

提交回复
热议问题