I needed to do this recently so I thought I would share my solution.
Create a 2D 3x3 Array
Going deeper requires additional nesting. Here is a 3x3x3
With a bit of meta programming we can write a function that takes an
Array describing our required xD array layout and generates it for us.
Oh yea, careful using the
Function constructor to create a new function, security and all that.