As shown in Variables, arrays are objects that hold a resizable ordered list of values.
Arrays can be declared in 2 ways. The first, and more straightfoward way, is using the [] operator. Then you can optionally - between [] - fill the array with the desired values, separating them using a comma.
Due to the object nature of arrays, it's also possible to create one by calling Array.Create, which takes a length and a initial value as parameters. The initial value gets used to fill the array up to the desired length.
You can read the value of an item held by an array by typing the array's name then the item's index between []. The first value of an array in HSL will always be 0.
Similarly, you can also set the value by adding the = operator to the end of the above syntax followed by the value you want.
In both cases, trying to access values greater than or equal to the array's length or below 0 results in an error.
In this section we'll show a few methods that can be used to insert or remove items inside an array, those being: Array.Push, Array.Pop, Array.Insert, Array.Erase, and Array.Clear. As mentioned previously, methods will be explained in future chapters.
You may find other methods accompanied by explanations in the Array page.
The Push method can be used to append values to the end of an array.
Pop, on the other hand, removes the last item inside an array, returning the removed value after.
Insert takes an index and a value as arguments. The value gets appended at the index defined by first argument. Using Insert shifts all the items after the specified index to the right to accomodate the new value.
As a counterpart, Erase removes any value specified in the index argument, shifting all the values after the index to the left.
Finally, Clear erases all the elements inside the array.