Arrays in AssemblyScript
There are two types of Arrays, that can easily be confused with each other. For the first part, there are Arrays like we know them from JavaScript - second, there are Arrays as they appear in C, with one huge difference: The Arrays in C are fixed in size. In AssemblyScript, these fixed Arrays are called static Arrays.
JS-like Arrays
Section titled “JS-like Arrays”First, let’s cover the “normal” arrays.
Creating Arrays
Section titled “Creating Arrays”There are two ways for creating arrays.
let numbers: i32[]numbers = [1, 2, 3]Or:
let numbers = new Array<i32>(3)
numbers[0] = 1numbers[1] = 2numbers[2] = 3Using Arrays in JavaScript
Section titled “Using Arrays in JavaScript”After importing the array from the file:
console.log(numbers.value)Static Arrays
Section titled “Static Arrays”Returning an Array
Section titled “Returning an Array”export function returnArr(num: i32): i32[] { const arr = new Array<i32>(3) arr[0] = num arr[1] = num arr[2] = num return arr}