title: Creating a variable name of a property in a JSON object
body: <p>I'm running this code.</p>
  
  <pre class="lang-javascript prettyprint-override"><code>var output = {"records": []};
  for(i = 0; i &lt; data.length; i++)
    output.records[i] = { propertyName : data[i][propertyName] }
  </code></pre>
  
  <p>I expected the output to be on the following form.</p>
  
  <pre><code>{ "cat" : "mjau" }
  { "dog" : "woff" }
  </code></pre>
  
  <p>Instead, I get to my surprise this.</p>
  
  <pre><code>{ "propertyName" : "mjau" }
  { "propertyName" : "woff" }
  </code></pre>
  
  <p>How can I get variable <em>propertyName</em>?</p>
  
  <p>I'm trying to create a parser that will create a number of records that are all <em>cat</em> but, when called from an other place, the records should have <em>dog</em> property instead. I wish to avoid creating two different code pieces for that.</p>
  
  <p>I've found <a href="https://stackoverflow.com/questions/12979335/creating-json-object-with-variables">this question</a>, which <strong>I suspect</strong> contains the answer to my issue. However, due to ignorance, I don't get it.</p>