1

I am reading the document about the smart contract in Near in Assembly Script. When reading about the Arrays in it. It said "there is two why to initialize an array"

  1. var arr = new Array<string>(10);
  2. var arr = Array.create<string>(10);

when I am trying the second option with create it gives me the following error:

Property 'create' does not exist on type 'typeof Array

can anyone help me?

Rasha
  • 73
  • 7
  • Does this answer your question? [Three different ways to instantiate Arrays in AssemblyScript](https://stackoverflow.com/questions/57966406/three-different-ways-to-instantiate-arrays-in-assemblyscript) – John Jan 04 '22 at 14:55

2 Answers2

0

I think maybe the documentation on NEAR should be updated, because according to The AssemblyScript Book, an array is created using your first example. The second example (using .create) is deprecated

From the docs

var arr = new Array<string>(10)
// arr[0]; // would error 
for (let i = 0; i < arr.length; ++i) {
  arr[i] = ""
}
arr[0]; // now it works 
John
  • 10,165
  • 5
  • 55
  • 71
-1

(edited) Try this line:

let testData = new Array<string>()
let data = Array.create<string>(10)

Try this way and let me know if its works!

Information link

euTIMER
  • 681
  • 3
  • 12
  • I do try it but it still give me the same error. – Rasha Dec 22 '21 at 07:26
  • Okey, please try this I found: [https://stackoverflow.com/questions/57966406/three-different-ways-to-instantiate-arrays-in-assemblyscript](https://stackoverflow.com/questions/57966406/three-different-ways-to-instantiate-arrays-in-assemblyscript) – euTIMER Dec 22 '21 at 07:31
  • let me know if this works! Thank you. – euTIMER Dec 22 '21 at 07:37
  • thanks. I read that link they write as an update that "Array.create deprecated and should not be used anymore." So I think I will stick with the first option and fill the element to the required length. – Rasha Dec 22 '21 at 07:47