Course of Raku / Essentials / Positional data types

Nested arrays

Arrays can contain any other data, including other arrays. To delimit the borders of the nested arrays, use square brackets:

my @table = 
    [1, 2, 3, 4],
    [10, 20, 30, 40],
    [100, 200, 300, 400];

It is also possible to have one more pair of brackets for the top-level array. The next example shows the same data structure as before.

my @table = [
    [1, 2, 3, 4],
    [10, 20, 30, 40],
    [100, 200, 300, 400]
];

To access inner items, add as many indices as needed. A single pair of square brackets goes down one level deeper into the structure:

say @table[0][3]; # Prints 4
say @table[2][1]; # Prints 200 

Practice

Complete the quiz that covers the contents of this topic.

Course navigation

Positional data types / Arrays   |   Positional data types / The @*ARGS array


💪 Or jump directly to the exercises to this section.

Translations of this page: EnglishDeutschEspañolItalianoLatviešuNederlandsБългарскиРусскийУкраїнська