How do you easily create empty matrices javascript?

前端 未结 17 1427
[愿得一人]
[愿得一人] 2020-12-04 16:29

In python, you can do this:

[([None] * 9) for x in range(9)]

and you\'ll get this:

[[None, None, None, None, None, None, No         


        
17条回答
  •  旧巷少年郎
    2020-12-04 17:01

    I'll give it my shot as well

    var c = Array;
    
    for( var i = 0, a = c(9); i < 9; a[i] = c(9), i++ );
    
    console.log( a.join(",") );
    //",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"
    

    Readable and maintainable !

提交回复
热议问题