Object access using variable

I am just curious, will this kind of syntax be supported later?

let personName = person["name"]

let nameKey = "name"
let personName = person[nameKey]

Currently, if I do that the compiler thinks that I am trying to access an array, so it asks me for an integer
Thanks

No this will probably never be allowed.
If you want to have dynamic access to a field of a JS object, and given the different fields are homogeneous, you’d better model them as Js.Dict.t<'a> (https://rescript-lang.org/docs/manual/latest/api/js/dict)

2 Likes

Noted,
I was trying to use it as dynamic access for the object from API.
Anyway, I still able to work around using the switch statement.

Thanks for the reply @tsnobip