How can I create a two dimensional array in JavaScript?

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

    Array(m).fill(v).map(() => Array(n).fill(v))
    

    You can create a 2 Dimensional array m x n with initial value m and n can be any numbers v can be any value string, number, undefined.

    One approach can be var a = [m][n]

提交回复
热议问题