Accessing JS array elements without Caml_array.get()

I have the following code:

let myArray = ["hello", "world"]
let firstItem = myArray[0]

In a previous version of ReScript this would generate:

var myArray = ["hello", "world"];
var firstItem = myArray[0];

With ReScript 9.1.2 it generates:

var myArray = ["hello", "world"];
var firstItem = Caml_array.get(myArray, 0);

Is there a syntax available that allows it to generate the previous output without the Caml_array.get() call?

Thanks

1 Like

In a previous version of ReScript this would generate?

Can you double check, this seems unlikely, since array indexing is always bounds checked.

There is a Belt.Array.getUnsafe which ignores bounds checking

2 Likes

Thank you @Hongbo

In the current docs, the example JS code shows the previous generated code. Not sure what version that might have been though.

But your suggestion is perfect, thanks.

1 Like