title: Javascript objects & loops
body: <p>Sorry for the broad question title.</p>
  
  <p>I'm building an app in Titanium and I'm currently integrating google maps with annotations - I'm grabbing the data from my API but I have hit a brick wall trying to make this easy for my self.</p>
  
  <p>For a foreword, the map module I use allows me to do the following:</p>
  
  <pre><code>mapView.addAnnotations([anno1,anno2,anno3]);
  </code></pre>
  
  <p>and</p>
  
  <pre><code>mapView.removeAnnotations([anno1,anno2,anno3]);
  </code></pre>
  
  <p>I would like to create a function that allows me to add the annotiations and remove them upon an user requested update of the map annotations.</p>
  
  <p>I'm currently at a point where I have this:</p>
  
  <pre><code>var annotations = {};
  
  for(c = 0; c &lt;= countedOffers; c++ ) {
      var offerName = offers[c]['offer_name'];
      var offerCat = offers[c]['offer_cat_id'];
      var offerlong = offers[c]['offer_long'];
      var offerlat = offers[c]['offer_lat']
  
      var anno = 'offer'+c;
  
      if(anno in annotations == false) {
          annotations['anno'+c] = {'name':offerName, 'offercat': offerCat, 'offerlng':offerlong, 'offerlat':offerlat};
      }
      if(countedOffers - c == 1) {
          loopThrough(annotations);
      }
  }
  </code></pre>
  
  <p>I can add the above annotiations by doing something like this:</p>
  
  <pre><code>var annotation = maps.createAnnotation({
  lat:,
  lng:,
  etc...
  });
  mapView.addAnnotation(annotation);
  
  function loopThrough(obj){
      for(var key in obj){
          if(!obj.hasOwnProperty(key)) continue;
          if(typeof obj[key] !== 'object'){
              Ti.API.error(obj[key]);
          } else {
              loopThrough(obj[key]);
          }
      }
  }
  </code></pre>
  
  <p>The Ti.API.error gives me something like this:</p>
  
  <pre><code>joshes big burger house
  1
  -1.2577
  51.7520
  joshes big burger house
  3
  -1.2577
  51.7520
  jj offer
  1
  -1.2577
  51.7520
  No Photo
  1
  -1.2577
  51.7520
  joshes web offer
  2
  -1.2577
  51.7520
  Joshes Web Offer
  3
  -1.2577
  51.7520
  </code></pre>
  
  <p>Which is fine, but I would like them to be inside of a variable or something I can loop through. I will always know how many I need to add and remove.</p>
  
  <pre><code>mapView.addAnnotations([anno1,anno2,anno3]);
  mapView.removeAnnotations([anno1,anno2,anno3]);
  </code></pre>
  
  <p>I was thinking I could implode (or something similar) and get the object keys and put them in the above add/remove annotations</p>
  
  <p>Sorry if anything is unclear, I'll update my question if needed.</p>