title: How to create auto key for jQuery object array in loop
body: <p>I'm trying to create a jQuery object array recursive using each loop.
  If key is the same I want to create another object with loop key</p>
  
  <p>I want to know what is the equivalent <code>$array[] = $ariable -&gt; '[]'</code></p>
  
  <p>I have <a href="http://jsfiddle.net/y0q11hek/3" rel="nofollow noreferrer">this jsfiddle</a>. How to prevent overwrite 'abc' instead overwrite with def which has same key</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 storevar = {}
  
  $('.element').each(function(index, element) {
   storevar[$(element).data('key')] = $(element).text()
  });
  
  console.log(storevar)</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;div class="results"&gt;
  &lt;/div&gt;
  
  &lt;span class="element" data-key="elementkey"&gt;abc&lt;/span&gt;
  &lt;span class="element" data-key="elementkey"&gt;def&lt;/span&gt;
  &lt;span class="element" data-key="elementkey1"&gt;ghi&lt;/span&gt;
  &lt;span class="element" data-key="elementkey2"&gt;jkl&lt;/span&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <pre><code>// this is now
  var wrong = {
     elementkey: "def", 
     elementkey1: "ghi", 
     elementkey2: "jkl"
  }
  
  // what i want
  var correct = {
     elementkey: {
        0: 'abc',
        1: 'def'
     }, 
     elementkey1: "ghi", 
     elementkey2: "jkl"
  }
  </code></pre>