Qingping Qingping - 5 months ago 21
TypeScript Question

How to use an object's value as the parameter for another object in Javascript?

If I have:

var key = "Section";
course.key = "101";

I get told
course.key is unidentified
. I'm trying to set
course.Section = "101"
. Is there anyway to pass key's value in the second line?


The property key of course is undefined. Use bracket notation.

course[key] = "101"

is the same as

course["Section"] = "101"