Skip to content
Jordan Leppert edited this page May 6, 2024 · 13 revisions

Arrays are constructed with square brackets, with a list of values inside it, separated by commas. For example, this contains the values 1 to 5:

[1, 2, 3, 4, 5]

The .. operator can be used in an array definition to make a range of numbers. For example, this creates the same list as in the previous example:

[1 .. 5]

The step keyword can be used to change the difference between each element in a range. For example, this creates an array with all the even numbers between 2 and 10:

[2 .. 10 step 2]

Ranges can be used multiple times in an array definition along with individual elements separated by commas, for example:

# This contains: 1, 2, 3, 4, 5, 9, 10, 12, 14, 16
[1 .. 5, 9, 10 .. 16]

Arrays aren't limited to numbers and there is no restriction to one type. The following is valid:

[123, 'hello', True]

Arrays can also contain arrays if you like, for example:

[[1, 2, 3], [4, 5, 6], [7, 8, 9]]