JavaScript JS : Create a multidimensional array of any size easily : and assign a fill value

JavaScript JS : Create a multidimensional array of any size easily : and assign a fill value

//like the BASIC DIM :) use: var multiDimensionalArray = DIM([7,8,9] , fill value if desired)
function DIM( arrayOfDimensions , theValue)
{
let localArrayOfDimensions = arrayOfDimensions.slice(); //must copy array as scope is global for arrayofdimensions
let returnArray = [];
if (localArrayOfDimensions.length === 0) //no more dimensions
{
return theValue;
if(typeof theValue === undefined)
{return undefined;}
else
{return theValue;}
}
let arraySize = localArrayOfDimensions.shift(); // size of current dimension
for (let arrayPointer = 0 ; arrayPointer < arraySize ; arrayPointer++)
{//for each array pointer in this array dimension, recusivly call DIM, and return and assign the value
returnArray[arrayPointer] = DIM( localArrayOfDimensions , theValue);
}
return returnArray; //return here if there are still more array dimensions
}