3

I'm trying to retrieve a variable from an object.

cell: (row: any) => `${row.testcolumn}`

My only issue is that I don't know what 'testcolumn' is ahead of time as I'm doing this dynamically. I'm not sure what to do, and the nested template string strategy I'm attempting will not compile.

cell: (row: any) => `${row.(`${varString}`)}`

I've also tried just using the variable name instead of nesting a template string, but that just looks for the varString value in the object, which doesn't exist. Is there any way I can use a nested literal to substitute the string value into the template literal and it still look for row.testcolumn instead of row.varString?

1
  • 1
    Would cell: (row: any) => `${row[varString]}` work? Maybe I have misunderstood. Commented Feb 14, 2018 at 22:02

1 Answer 1

7

It is same for template literals as for regular JS. Object properties can be retrieved dynamically with bracket notation, row[varString].

It will be:

cell: (row: any) => `${row[varString]}`
Sign up to request clarification or add additional context in comments.

1 Comment

Still pretty new to this stuff, I appreciate it!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.