Reason For Anwser
#Reason For Anwser ThereThere are good answers here but as JavaScript has changed here is an additional method of tackling this problem with some of the updated features in JavaScript.
function nArray (dem, size=dem, fill=null, currDepth=0) { const arr = new Array(size).fill(fill); return (currDepth+1 === dem) ? arr : arr.map(i => nArray(dem, size, fill, currDepth+1)); }; Notes
dem is the dimensions of the array.
size is the size of each dimension by default it is the dem value.
fill is the value that will be the default filled value.
currDepth is not to be used it is for the recursive nature of the function.