title: Build an object dynamically
body: <p>I want to create an object dynamically in typescript / javascript. I have an array <code>reqParam</code> in an object env that might look like this: <code>env = {reqParams : ['fromTime', 'toTime']}</code> and it is passed to my initialising function to build an obect dynamically</p>
  <p><code>const myObject = _initObject(env.reqParams);</code></p>
  <p>I've started the function, but I can't figure out how to get the key and values into the new object properly.</p>
  <pre><code>private _initObject(raqParams: any) {
      let requestTemplate = {
        bodyjson : &quot;$util.escapeJavaScript($input.json('$'))&quot;,
        &quot;cognitoUserId&quot;: &quot;$context.authorizer.claims.sub&quot;, 
        &quot;cognitoUserEmail&quot;: &quot;$context.authorizer.claims.email&quot;
      };
      reqParams.forEach(param =&gt; {
        // build new item
        let templateEntry = &quot;$input.params('`param`')&quot;;
        // Put new item into object
        requestTemplate[`param`] = templateEntry;
      });
  }
  </code></pre>
  <p>Hopefully, you can see what I'm trying to achieve. For example, here's the desired outcome for 2 reqParams : fromTime and toTime:</p>
  <pre><code>      {
          bodyjson : &quot;$util.escapeJavaScript($input.json('$'))&quot;,       
          &quot;fromTime&quot;: &quot;$input.params('fromTime')&quot;,
          &quot;toTime&quot;: &quot;$input.params('toTime')&quot;,
          &quot;cognitoUserId&quot;: &quot;$context.authorizer.claims.sub&quot;,
          &quot;cognitoUserEmail&quot;: &quot;$context.authorizer.claims.email&quot;
        }
  </code></pre>