Casper Alant
Casper Alant

Reputation: 462

How to access a member using a variable with Flux

According to the docs, you can use square brackets for member access. However, when I try to do this using a variable it results in the errors below.

a = "ABC"
b = "DEF"

//This works
calc = (r) => r.ABC - r.DEF

calc = (r) => r["ABC"] - r["DEF"]

//However, I can't find a way to access the members using the variables

calc = (r) => r["${a}"] - (r["${b}"]
> type error @8:23-8:36: expected int but found string


calc = (r) => r[a] - r[b]
> type error @8:23-8:31: expected int but found string

How do you access members using a variable?

Upvotes: 1

Views: 633

Answers (1)

Casper Alant
Casper Alant

Reputation: 462

Sorry - the same docs I referenced had the answer:

It is not possible to access a record’s property using an arbitrary expression.

Upvotes: 1

Related Questions