title: Dynamically create javascript object
body: <p>I have below code in which i need to create a dynamic object</p>
  
  <pre><code>let response = {};
  const process = (key, value) =&gt; {
  if (key == FieldMapping[key]) {
      response = {
          ...response,
          key : value
      }
      console.log(key + " : " + value);
  }
  }
  </code></pre>
  
  <p>In the above code, i want to pass <code>key</code> as property of new object and <code>value</code> as value and keep all the previous added property and its value but it's not persisting the previously added property. Also <code>FieldMapping[key] : value</code> is giving compilation error .What's wrong here?</p>