Arrays
An array is a data structure that holds a number of values allowing them to be accessed by their index.
var arr = [1, 2, 3];+ Operator and Arrays
Section titled “+ Operator and Arrays”Two arrays can be concatenated with the + operator.
var arr1 = [1, 2, 3];var arr2 = [4, 5, 6];var arr3 = arr1 + arr2; // [1, 2, 3, 4, 5, 6]
## Index Access
A value in an array can be accessed using square bracket notation.
```qlvar arr = [1, 2, 3];var first = arr[0]; // 1Additionally, negative indices can be used to access elements starting at the end.
var arr = [1, 2, 3];var last = arr[-1]; // 3With either positive or negative indicies, out-of-bound numbers will return nil.
var arr = [1, 2, 3];var out_of_bounds1 = arr[3]; // nilvar out_of_bounds2 = arr[-4]; // nilnil Safe Index Access
Section titled “nil Safe Index Access”If an array is possibly nil, the get method can be combined with optional chaining.
var maybe_arr = nil;var maybe_first = maybe_arr?.get(0); // nilProgramatically Creating Arrays
Section titled “Programatically Creating Arrays”It may not always be possible to declare an array as a literal. In those cases, the array_of function can be used to create an array of a specified length. When no factory function is specified, each element of the array will be equal to it’s index.
var big_array = array_of(1000);var big_array_doubled = array_of(1000, (value) -> value * 2);