title: Iterating JavaScript object with strings as keys
body: <p>I am building a JavaScript array, which has strings as keys.</p>
  
  <p>The array should have an object at every entry. My object looks like this (a <code>console.log</code> of my variable <code>rIds</code>):</p>
  
  <p><img src="https://i.stack.imgur.com/XtdhP.png" alt="Firebug screenshot of my variable"></p>
  
  <p>Now, the length of this object is 0, which makes it impossible to iterate it.</p>
  
  <p>I want to iterate every key, so I can retrieve and access my list of ids (<code>rIds[key].productIds</code>).</p>
  
  <p><strong>Code</strong>:</p>
  
  <pre><code>var rIds = [];
          var response = RR.data.JSON.placements;
  
          console.log(response);
          $(response).each(function (placementId) {
              var placement_name = this.placement_name;
  
              rIds[this.placement_name] = {
                  productIds: []
              };
  
              $(this.recs).each(function (recIndex) {
                  var pid = this.pid;
                  pid = getRandomId(19341610, 19341746);
                  rIds[placement_name].productIds[recIndex] = pid;
              });
          });
  
          var count = '&lt;%=ViewBag.Get("RecommendationCount") %&gt;';
  
          console.log(rIds);
          console.log(rIds.length);
          $.each(rIds, function (index, val) {
              console.log(val);  // This should work as expected.
          });
  </code></pre>
  
  <p><strong>What did I try?</strong></p>
  
  <p>I found the following snippet, which does not work in IE8. However, this does not really help be, even though <code>Object.keys(rIds).length</code> results in the correct length.</p>
  
  <pre><code>for (var index = 0; index &lt; Object.keys(rIds).length; index++) {
              console.log(rIds[index]);
          }
  </code></pre>
  
  <p>However, this code does not make my access the object.</p>
  
  <p><strong>Tl;dr &amp; question</strong></p>
  
  <ul>
  <li>How do I iterate my JavaScript object which has strings as keys, so I can access the individual entries?</li>
  </ul>