title: Is there a way to iterate Array() having string keys as index in Javascript
body: <p>i have a code where i am creating a two dimensional array by using new Array(); here is my Code where i am getting some values from some REST api and manipulating values like this as shown in the code below</p>
  
  <p>i have tried to iterate the object i am creating using available help from stack-overflow for the problems that are posted previously by other users, i.e trying to iterate array with key value pairs, using foreach loop or using key in object syntax with For loop.</p>
  
  <pre><code>    var CCTVCounterDictionary = new Array();
      var InitCCTVCounter = function (type, zoneName, quantityCCTV) {
          if (CCTVCounterDictionary[type] == undefined) {
              CCTVCounterDictionary[type] = new Array();
              if (CCTVCounterDictionary[type][zoneName] == undefined) {
                  CCTVCounterDictionary[type][zoneName] = new CCTVCounter(type, zoneName, 0);
                  CCTVCounterDictionary[type][zoneName].Increment(quantityCCTV);
              }
          }
          else if (CCTVCounterDictionary[type][zoneName] == undefined) {
              CCTVCounterDictionary[type][zoneName] = new CCTVCounter(type, zoneName, 0);
              CCTVCounterDictionary[type][zoneName].Increment(quantityCCTV);
          }
          else {
              CCTVCounterDictionary[type][zoneName].Increment(quantityCCTV);
          }
      };
  </code></pre>
  
  <p>and here is my js class that i am using to call Increment function for the object CCTVCounter that is being assigned to string index of each second dimension of array</p>
  
  <pre><code>    function CCTVCounter(type, zon, counter) {
          this.CCTVType = type;
          this.ZoneName = zon;
          this.CCTVCount = counter;
      }
      CCTVCounter.prototype.Increment = function (incrementBy) {
          if (incrementBy == undefined)
              this.CCTVCount++;
          else
              this.CCTVCount += parseInt(incrementBy);
      }
  </code></pre>
  
  <p>problem with this approach is that the length of my array stays 0 and if i try to iterate the array using foreach it doesn't seem to find key in CCTVCounterDictionary  with foreach loop or for loop syntax.</p>
  
  <p>i am trying to find help for a piece of code to be able to iterate this array as shown in figure above but i am not able to figure it out how. any help is highly appreciated.</p>
  
  <p>Below i am including log for how the output is being rendered by the code that is creating a 2 dimensional array</p>
  
  <pre><code>    SmartEnforcement.js: 202[] Banjir: Array(0) undefined: CCTVCounter {
          CCTVType: "Banjir",
          ZoneName: undefined,
          CCTVCount: 264
      }
      length: 0 __proto__: Array(0) Cadangan: Array(0) undefined: CCTVCounter {
          CCTVType: "Cadangan",
          ZoneName: undefined,
          CCTVCount: 26
      }
      length: 0 __proto__: Array(0) Sediada: Array(0) PJS: CCTVCounter {
          CCTVType: "Sediada",
          ZoneName: "PJS",
          CCTVCount: 368
      }
      PJU: CCTVCounter {
          CCTVType: "Sediada",
          ZoneName: "PJU",
          CCTVCount: 981
      }
      SEKSYEN: CCTVCounter {
          CCTVType: "Sediada",
          ZoneName: "SEKSYEN",
          CCTVCount: 504
      }
      SS: CCTVCounter {
          CCTVType: "Sediada",
          ZoneName: "SS",
          CCTVCount: 816
      }
      length: 0 __proto__: Array(0) length: 0 __proto__: Array(0)
  </code></pre>
  
  <p>Here is how i am invoking my main function to call the InitCCTVCounter</p>
  
  <pre><code>    InitCCTVCounter(marker.Type, f.attributes.ZON, marker.TotalCCTVS);
  </code></pre>