title: Create JSON Array key dynamically in JavaScript
body: <p>I'm Having a JSON that is getting creates in <code>for-loop</code>.</p>
  
  <p>Here my main requirement is to create the <code>Key</code> from a predefined variable.</p>
  
  <p>Here is the code that I'm using.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var rows =["Hello Trt", "Ho there", "I'm up"];
  var name="Hello";
  var jsonData = {};
  var intentName=[];
  var mainPersonel = {};
  var intents = {};
  intents.intentName = rows;
  mainPersonel.intents=intents;
  console.log(JSON.stringify(mainPersonel));</code></pre>
  </div>
  </div>
  </p>
  
  <p>Looking into the other SO posts, I'm able to find on how can I replace <code>intents</code> variable, but here in my case, I want to replace <code>intentName</code> with <code>name</code> in the output.</p>
  
  <p>Expected output is </p>
  
  <pre><code>{"intents":{"Hello":["Hello Trt","Ho there","I'm up"]}}
  </code></pre>
  
  <p>Please let me know on how can I achieve this.</p>
  
  <p>Thanks</p>