Good evening programmer community! Is it possible to create a one liner array in Javascript. To make my question clearer, I would like to emulate the following one liner that I usually do in Python on Javascript:
>>> arrAy=[['_' for i in range(10)] for j in range(10)]
which gives the following result:
>>> for i in arrAy:
print(i)
>>> [['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_'],
['_', '_', '_', '_', '_', '_', '_', '_', '_', '_']]
Thank you
;sofor(var i = 0; i < arrAy.length; i++) { console.log(arrAy[i]); }is validfor (var i = 0; i < 10; i++) for (var j = 0; j < 10; j++) doSomething(i, j);is definitely a onelinervar myArr = new Array(10).map(function() { return new Array(10).map(function() { return "_"; }); });but due to the way thatnew Array()initilizes the array withundefinedvalues and howmap()only runs the provided function on array indexes with values, it doesnt :(. You could dovar anArray = [[],[],[],[],[],[],[],[],[],[]].map(function(arr) { return ["_","_","_","_","_","_","_","_","_","_"]; });though :)for ( i amount of iterations ) {for ( j amount of iterations ) { '_' }}Thank you.