0

I would like to update property value, which has dynamically set property name, but I can't figure out how to do it.

So I have an object like this, which has dynamically set property name (not value, the 'asd' - property name).

{period: "2020", asd: "5"}

Object is created like this:

let myTestObject = {
  period: "2020",
  [name]: "5"
};

Now when I want to update this object, I would assume it works like this, but it doesn't:

myTestObject.[name] = "new value"
Mystery Man
  • 33
  • 1
  • 5
  • Does this answer your question? [Dynamically access object property using variable](https://stackoverflow.com/questions/4244896/dynamically-access-object-property-using-variable). (It's either a dot or brackets, not both. `myTestObject[name] = "new value"` or `myTestObject.asd = "new value"`) see: [Working with objects](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects) – pilchard Jun 27 '21 at 22:31
  • Yes, thanks. The issue was somewhere else why it wasn't updating though, but at least I now know the right way. – Mystery Man Jun 27 '21 at 22:43

0 Answers0