title: Creating multidimensional JavaScript arrays of any size
body: <p>I would have thought that a function to Create multidimensional JavaScript arrays of any size would be very handy. But I have not found one. So I created my own.</p>
  
  <p>Would using array.map work in this case? If so I imagine it would be less 'logical' looking. </p>
  
  <pre><code>//like the BASIC DIM :) use: var multiDimensionalArray = DIM([7,8,9])
  function DIM(arrayOfDimensions) {
    let localArrayOfDimensions =  arrayOfDimensions.slice(); //must copy array as scope is global for arrayofdimentions
    let returnArray = [];
    if (localArrayOfDimensions.length === 0) {
      return undefined; //no more dimensions
    }    
    let arraySize = localArrayOfDimensions.shift(); // size of current dimension
    for (let arrayPointer = 0 ; arrayPointer &lt; arraySize ; arrayPointer++){
      //for each array pointer in this array dimension, recusivly call DIM, and return and assign the value 
      returnArray[arrayPointer] = DIM( localArrayOfDimensions ); 
    }
    return returnArray; //return here if there are still more array dimensions
  }
  
  var test = DIM([5,3,2]); 
  test[4][2][1] = 'aaaasss'; 
  var t = test[4][2][1];
  </code></pre>