Object.assign( ) key / value syntax

javascript

Solution

`[key]` is an ES6 computed property. Here is a basic example:

let obj = {
  [1 + 2]: 'Hello!'
};

console.log(obj[3]);

Problem

The following function updates an object with a new key and value: ``` function updateObjectWithKeyAndValue(object, key, value) { return Object.assign({}, object, { [key]: value }) } ``` What I don't understand is why `key` and `value` look different. Why is `key` in brackets when `value` isn't?

Original source

Related problems