What i want is something i do every day in Python. In JS it does not work, most probably because i suck in JS.
This is the Python code that would do what i want:
>key = 'just_a_key'
>value = 5
>dict = {key: value}
>dict
{'just_a_key':5}
>dict['just_a_key'}
5
This does not work in JS, the key there will be just named ‘key’. I know this is because i’m not really creating a dictionary here, but using json to create an object when i write the same code. So my question now is: How can i programmatically name the objects “keys” (or properties?) in JS?
Like this:
JavaScript does not evaluate expressions for property names in its object literal notation, but it does if you use the square bracket form of the object member operator.
MDN Member Operators