[Question]
  [
Write a program or function that, given an integer `n`, construct an array with `n` dimensions of `n` length, where each element is an identifier of its own coordinates. That is, starting with one array, populate it with `n` arrays, where each of those contain `n` more arrays, up to a depth of `n-1`. The elements of the deepest arrays are the coordinates describing where they are in the full array.
Some examples in case my explanation was confusing.
### n = 1
```
["1"]
```
### n = 2
```
[
 ["11", "12"],
 ["21", "22"]
]
```
### n = 3
```
[
  [
    ["111","112","113"],
    ["121","122","123"],
    ["131","132","133"]
  ],
  [
    ["211","212","213"],
    ["221","222","223"],
    ["231","232","233"]
  ],
  [
    ["311","312","313"],
    ["321","322","323"],
    ["331","332","333"]
  ]
]
```
Here, "321" means it is the 1st element of the 2nd element of the 3rd array.
### Rules:
* Coordinates and dimension (`n`) can be either 0 or 1 indexed
* You may assume `n` is single digit, below 10 for both indexing options to prevent ambiguous outputs
* IO is flexible.
	+ In particular, coordinates can be arrays, strings etc. as long as they are clear. "321" => [3,2,1]
	+ Output can be integers in base 10 with or without leading zeroes.
	+ Coordinates can be in reverse order if you wish, as long as it is consistent. "321" => "123"
	+ Output doesn't necessarily have to be an array structure in your language. As long as there's clear distinct markers for the start of an array, end of an array and for separating elements.
	+ The output for `n=1` can just be 1
	+ If your output is atypical, make sure to explain the format.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest solution in each language wins!
  
[Answer]
# [Dyalog APL](https://www.dyalog.com/), ~~5~~ 3 bytes
```
⍳⍴⍨
```
-2 bytes thanks to [FrownyFrog](https://codegolf.stackexchange.com/users/74681/frownyfrog)
[Try it online!](https://tio.run/##SyzI0U2pTMzJT/@v8ahvql/wo941mnqPevvUgTznSHX14sScEnX1R90tQH6wq16os68LkNs2ISm/QiE/D8jsWpyal5iUkxrs6BMCUta7Rl3hUe9chYKi1JKSSgWgutRihcSi/NK8FIWSjFSF/NKSgtKS/2lAMx71bn7Uu@VR74r//9MUDLnUdXV11bnSFIzgLGM4ywQA "APL (Dyalog Unicode) – Try It Online")
`⍳` gives all the indices given the shape of an array. e.g. [2 3](https://tio.run/##SyzI0U2pTMzJT/8PBI96NxspGAMA).  
`⍴` reshapes the right arg to be the size of the left arg. `⍨` makes both be the right arg.
[Answer]
# [Python 3](https://docs.python.org/3/), 56 bytes
```
f=lambda n,*l:len(l)//n*l or[f(n,*l,k)for k in range(n)]
```
[Try it online!](https://tio.run/##FcgxDoAgDADAr3RsCQkDm4kvMQ4YqRJqIQ2Lr8d44/V33E3jnLxKeo4zgXoni2RFoRDUCTTbGP/1lbgZVCgKlvTKqLTPbkUHMkai@QE "Python 3 – Try It Online")
Mr. Xcoder saved 2 bytes switching to Python 3 for starred unpacking.
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~32~~ 22 bytes
-10 bytes thanks to @alephalpha
```
Array[List,#~Table~#]&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n2ar8d@xqCixMtons7hER7kuJDEpJ7VOOVbtv6Y1V0BRZl5JdJqDso6CUkyeUqyavkM1F5ehDpeRDpcxF1ftfwA "Wolfram Language (Mathematica) – Try It Online")
[Answer]
# [J](http://jsoftware.com/), 18 bytes
```
,"1/^:(]{:)~@,.@i.
```
[Try it online!](https://tio.run/##y/qfkq8Qb6iQUpRfoKCeZqunrqOQl1@ap5CSmpaZl/pfR8lQP85KI7baSrPOQUfPIVPvvyYXV2pyRr5CmoIhhGGpoq6rDhMzwiJmjCFmo2QIFDfh@g8A)
Iterative solution, no built-in cartesian product. This is what peak J looks like.
```
                       input                                    2
                i.     range                                 0, 1
             ,.@       reshape each element
                       into a one-dimensional array        [0],[1]   (A)
    ^:(]{:)            (input−1) times...             (1 iteration)
,"1/       ~@             prepend the contents of each 1d array in A    |
                          to every 1d array from the previous iteration,|  
                          assembling the results for each A[n] into     |!CANTEXPLAINTHIS!
                          a larger array                                |
                                                         [ [0,0],       |
                                                           [0,1] ],     |
                                                         [ [1,0],       |
                                                           [1,1] ]      |
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~8~~ 7 bytes
```
ṗ³s³$³¡
```
[Try it online!](https://tio.run/##ARgA5/9qZWxsef//4bmXwrNzwrMkwrPCof///zI "Jelly – Try It Online")
**Explanation**
Use argument 2 as an example.
```
ṗ³s³$³¡   
ṗ        Cartesian power with power
 ³       2 (the argument). Autoranges the left arg.
         Yields [[1,1],[1,2],[2,1],[2,2]]
    $³¡  Do 2 times:
  s³     Split into segments of length 2. 
         This last step molds the array of indices into the proper shape.
```
---
If `¡` didn't vary it's right argument over iterations for dyads then this would be 4 bytes: `ṗs³¡`
[Answer]
# J, 13 bytes
```
[:{[;/@$,:@i.
```
[Try it online!](https://tio.run/##y/qvpKeepmBrpaCuoKNgoGAFxLp6Cs5BPm7/o62qo631HVR0rBwy9f5rcnGlJmfkK6QpGEIY6rq66jAhI0whY67/AA "J – Try It Online")
Interesting this is so much longer than the APL answer (though that may be my inability to see a better translation)
## explanation
```
[: { [ ;/@$ ,:@i.
     [                NB. the argument
            ,:@i.     NB. range 0..arg, considered as one item: ,: is "itemize" 
          $           NB. repeat the right range the left number of times
       ;/@            NB. and then put boxes around them. so, eg, if we had
                      NB. an arg of 3, now we have the list of boxes 
                      NB. [0 1 2][0 1 2][0 1 2]
[: {                  NB. { is "Catalog", it creates the cartesian product
                      NB. in exactly the format we desire.
```
[Answer]
## MATLAB, 92 89 55 bytes
I have a different answer having re-read the rules of the challenge, but I'll leave the previous attempt below as it's different and still fun to look at.
```
reshape(string(dec2base(0:n^n-1,n+(n<2))),[~(1:n)+n 1])
```
**Explanation**
```
                        0:n^n-1                        % [0,1,...,n^n-1]
               dec2base(       ,n+(n<2))               % Put into base n (base 2 if n=1)
        string(                         )              % Convert to strings
                                          [~(1:n)+n 1] % Dimension array [n,n,...,n] (length n)
reshape(                                 ,            )% Use dim array to reshape
```
This outputs an n-dimensional array of strings which are 0 indexed.
**Previous Answer (89 bytes)**
My first golf! This can likely be reduced more but I thought I'd post what I've got.
```
x=(1:n)';for d=2:n;y=((1:n)*10^(d-1));o=[];for p=1:nnz(y);o=cat(d,o,(x+y(p)));end;x=o end
```
**Explanation**
```
x=(1:n)';                       % Create array x=[1,2,...n]'
for d=2:n                       % d for dimension
    y=((1:n)*10^(d-1));         % Creates an array for each d where
                                %   y=[10,20,30,...] for n=2
                                %   y=[100,200,...] for n=3 etc.
    o=[];                       % o for output
    for p=1:nnz(y)              % For each value of y
        o=cat(d,...             % Concatenate in the dth dimension:
            o,...               % - The current output
            x+y(p));            % - The sum of
                                %   - The array from the last dimension
                                %   - The current value in y (e.g. 100)
    end
    x=o                         % Send the output to x for the next loop
end
```
Outputs x at the end to give solution
Similar to the other MATLAB post, the output is an n-dimensional array, except it uses numbers to display the coordinates. It works for any value, although because loops are bad in MATLAB it begins to slow down significantly around n = 8.
Edit: -2 bytes thanks to Luis Mendo. Also removed final semicolon to print the output.
[Answer]
# [Rust](https://www.rust-lang.org/), ~~201~~ ~~176~~ ~~167~~ ~~166~~ 154 bytes
```
enum L{S(String),L(Vec<L>)}fn
h(n:u8,d:u8,s:&str)->L{if
d<1{L::S(s.into())}else{L::L((0..n).map(|i|h(n,d-1,&format!("{}{}",s,i))).collect())}}|n|h(n,n,"")
```
[Try it online!](https://tio.run/##HU6xasMwFNz1FaoD4T1QRNOpKGm6ZNRm6FI6uLaUCOTnIMlZZH27K/eG4zjujgtzTKslPnaOAHlmzJvELf@ocvc9mOCeBq7md77hz2poHrnOLbQpOLqh0PBl@rO@YLHE7kBqfhfDRlHtYwp4uOjsLBvOx6yVaiFKR2kCxGJ8NJunAV6lJJRj94DFLXVEDIej2NspjF16gSaXXBoRhUNE2U/emz5tC2Wh/zSJpsG1nBiveNRfydNWU7vP2uMW3hBPrKx/ "Rust – Try It Online")
The output type is a sum type with two variants as the language is strictly typed. It can be either `L`, which is a list type containing this sum type or `S` which is a result type (a string). The result can look like this.
```
L::L([
 L::L([ L::S("00"), L::S("01") ]),
 L::L([ L::S("10"), L::S("11") ]),
])
```
Also, reformatted using `rustfmt`:
```
enum L {
    S(String),
    L(Vec<L>),
}
fn h(n: u8, d: u8, s: &str) -> L {
    if d < 1 {
        L::S(s.into())
    } else {
        L::L(
            (0..n)
                .map(|i| h(n, d - 1, &format!("{}{}", s, i)))
                .collect(),
        )
    }
}
|n| h(n, n, "")
```
[Answer]
# [R](https://www.r-project.org/), 102 bytes
```
function(n,m=array(T,rep(n,n)))`if`(n<2,'1',{m[]=apply(which(m,T)[,`[<-`(1:n,1:2,2:1)],1,toString);m})
```
[Try it online!](https://tio.run/##dcuxCoMwEIDh3adwyx2cQ6KTNU9RNyskSFMDzSkhpUjps6edW/Jv//DF7HR2D16S3xiYgrYx2gNGitf9@4yIxjsDPCgSUtArTLO2@34/4Ln6ZYVAI05kpqExIHsm2StSvcSZJKXtnKLnG57CG/NiE4jmp5q1rJu/LiywciCxKilVVqqs2rJqy6orqw7zBw "R – Try It Online")
* 1-indexed, reversed
* unfortunately R stores matrix by column, otherwise we could go down to [73 bytes](https://tio.run/##dcsxDoMwDIXhnVOwYUvOEGAkpyhbOxBFBCJVJoqCSk6fMrfyP703fKl6U/3JLoeDgekyNiVbYKa0xvszIi7PSS1wUZnUZw9uv@eMZGN8FyikKR@PnAJviNXZDJ36qWWjW/XXiztsPGhsJNXLqpfVIKtBVqOsRqxf "R – Try It Online")
* -9 bytes saved thanks to @Giuseppe suggestion to use `which` array 
indexing
[Answer]
# Java 10, 144 bytes
The solution is method `f`. It produces a string representation of the array.
```
String h(int n,int d,String s){if(d<1)return s;var r="[";for(int i=0;i++<n;)r+=h(n,d-1,s+i)+",";return r+"]";}String f(int n){return h(n,n,"");}
```
[Try It Online](https://tio.run/##NU/NasMwDD6nTyF8srEbFnZ0/Ag79VhK8eKkdZcoxXZSRsizZ67jgZDEJ74fPfSsjw/zsz2n79420PTae/jSFmHZTsFZvMGdWgyA4t2NyKBni@2oqSvm2jA5BC9n7cApciayG13iWPUhLec1Sua4ulMU5lgJzy3jRBCZmY6TC5FrFu52N7bk65uFghAm163IKX3QIY55tAaGmJXu3PMFtLt5BsuhKNIPAyjA9pUeokxGOEaD5NBo317juZJ5rRV8/u884rtMcfr1oR3KcQrlM5qEHmm2YzCUHU0ElrTXQ6x1@wM)
## Ungolfed
```
String h(int n, int d, String s) {
    if (d < 1)
        return s;
    var r = "[";
    for (int i = 0; i++ < n;)
        r += h(n, d - 1, s + i) + ",";
    return r + "]";
}
String f(int n) {
    return h(n, n, "");
}
```
## Acknowledgments
* byte savings thanks to [Konrad Borowski](https://codegolf.stackexchange.com/users/3103)
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 7 bytes
```
LsãsGsô
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fp/jw4mL34sNb/v83BgA "05AB1E – Try It Online")
**Explanation**
```
L          # push range [1 ... input]
 sã        # input repeated cartesian products of the list
   sG      # input - 1 times do:
     sô    # split into input parts
```
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), ~~62~~ ~~60~~ 58 bytes
```
f=(n,i=n,s='')=>i?[...Array(n)].map((_,j)=>f(n,i-1,s+j)):s
```
[Try it online!](https://tio.run/##FYvBCsIwEAV/ZW/dmDRQ6Kk1inf/QERim2hi3ZSkCiJ@e0xPD2bmef3WaYhuXmoKo8nZKiThFImkqoqpndufpJSHGPUHiZ3lU8@IF@GLsmtZNyJxz1iXcm9DBHSgoOnBwVZBW5ZzBkOgFCYjRxfRomMCvnCNRj@Ohm7LvSv1Zn1yaIsbzbwyek0T/Fif/w "JavaScript (Node.js) – Try It Online") Output is 0-indexed. Edit: Saved 2 bytes thanks to @JoKing and a further 2 bytes thanks to @Arnauld.
[Answer]
## MATLAB, 116 108 104 bytes
I feel like there must be a shorter way to do this, given MATLAB's affinity toward multi-dimensional matrices... Thanks to Luis for the 4 bytes from some short-handing
```
a=~(1:n)+n;c=cell(1,n);[c{:}]=ind2sub(a,1:n^n);reshape(arrayfun(@(varargin)[varargin{:}],c{:},'un',0),a)
```
**Explanation**
```
% For using twice, define the array of dimension sizes [n, n, .., n]
a=~(1:n)+n;
% To group variable number of outputs from ind2sub into a cell array
c=cell(1,n);   
% Convert linear indices to self-describing coordinates
[c{:}]=ind2sub(a,1:n^n);     
% reshape to make it the n-dimensional array
% arrayfun to loop over the numerous ind2sub outputs simultaneously
% varargin and {:} usage to account for various numbers of inputs
reshape(arrayfun(@(varargin)[varargin{:}],c{:},'uni',0),a)
```
The output is an n-dimensional cell array, where each element is an array of the coordinate values. Works for any `n` without ambiguity because of the numeric array output, so long as an `n^(n+1)` element array can be stored in RAM!
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), 26 bytes
```
Ｎθ≔ＥＸθθ⪫⪪◧⍘ιθθ ¦0υＦθ≔⪪υθυυ
```
[Try it online!](https://tio.run/##S85ILErOT8z5/98zr6C0xK80Nym1SKNQ05rLsbg4Mz1PwzexQCMgvxwkqKNQqKmj4JWfmacRXJCTWaIRkJjik5pWouGUWJwaXFKUmZeukQlRBMJKCkog0kBJE0iVAk1Myy9SABqtADUZYkYpRDFIPgBoAlBA0/r/f@P/umU5AA "Charcoal – Try It Online") Link is to verbose version of code. Explanation:
```
Ｎθ
```
Input `n`.
```
≔ＥＸθθ⪫⪪◧⍘ιθθ ¦0υ
```
Generate all `nⁿ` `n`-digit numbers in base `n`.
```
Ｆθ≔⪪υθυ
```
Split them `n` times into an `n`-dimensional array where each dimension is of size `n`.
```
υ
```
Print the array. The default output format is each element on its own line, then each block of `n` lines is terminated by a blank line, then each block of `n` blocks of `n` lines is terminated by a second blank line, and so on up to `n-1` blank lines at the top level.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
ṗṁẋ`ŒṬ$
```
[Try it online!](https://tio.run/##y0rNyan8///hzukPdzY@3NWdcHTSw51rVP4fbgcxZvz/bwwA "Jelly – Try It Online")
]