0

Assemblyscript initializes typed arrays with their length, like this:

var arr = new Uint8Array(2);

Suppose I want to seed this array with some values, like [12, -47, 91], how would I do it?

Armand
  • 1
  • 1

2 Answers2

0

I found the answer myself. One must use StaticArray like this:

var arr:StaticArray<i8> = [12, -47, 91];
Armand
  • 1
  • 1
0

You can use this approach if you need typed array instead StaticArray

const arr = new Uint8Array(3);
arr.set([12, -47, 91]);
MaxGraey
  • 351
  • 2
  • 6