myObj[prop] = value;
That should work. You mixed up the name of the variable and its value. But indexing an object with strings to get at its properties works fine in JavaScript.
More Related Contents:
- the value of the property “if” is null or undefined, not a Function object [closed]
- How do I remove a property from a JavaScript object?
- Dynamically access object property using variable
- Test for existence of nested JavaScript object key
- Sorting object property by values
- How to create an object property from a variable value in JavaScript? [duplicate]
- Remove array element based on object property
- Is it possible to get the non-enumerable inherited property names of an object?
- Getting the object’s property name
- Access object properties within object [duplicate]
- Access JavaScript property case-insensitively?
- Watch for object properties changes in JavaScript [duplicate]
- how to access object property using variable [duplicate]
- Can a JavaScript object property refer to another property of the same object? [duplicate]
- How do I access properties of a javascript object if I don’t know the names?
- Get object property name as a string
- How to create Javascript constants as properties of objects using const keyword?
- Accessing an object property with a dynamically-computed name
- How to prevent automatic sort of Object numeric property?
- JavaScript object literal length === undefined?
- Are there limits to the number of properties in a JavaScript object?
- How to get the size of a JavaScript object?
- Object property name as number
- How to get object length [duplicate]
- Reverse of JSON.stringify?
- How to write data to a JSON file using Javascript
- Getting a list of statics on an ES6 class
- How can I convert a jQuery object to an Element?
- Sort a dictionary by value in JavaScript
- Best way to flatten JS object (keys and values) to a single depth array