title: How to iterate an array of javascript objects
body: <p>I'm using a server script to retrieve objects from a mongo database. It returns a string (I think it is a text representation of an object array). I convert it using eval and this seems to work ok. What I'm wondering is how to iterate this to get each object, and then the _id property from each object.</p>
  
  <p>I've tried iterating using for i &lt; obj.length but it says that obj.length is undefined. I've looked at other code examples online and they always show iterating the properties for one object.</p>
  
  <p>To tell you the truth, I'm not even sure what this is. Is it an object containing an array, an array containing obbjects? I'm a bit lost. Any nudge in the right direction would be appreciated.</p>
  
  <pre><code>query[{
      _createdAt : {
          '$date' : '2013-08-31T10:17:08.842Z'
      },
      _id : '5221c2a4e4b0899403d2afb5',
      _updatedAt : {
          '$date' : '2014-03-03T19:36:58.681Z'
      },
      acl : {
          '52194f94e4b0899403cbf411' : [ Object ],
          '' : [ Object ]
      },
      available : true,
      category1 : 'Pasta',
      description : 'The classic dish',
      entity_code : 'stef1',
      name : 'Spaghetti',
      price : 23,
      productlist_code : 'A',
      sort_order : 3
  }, {
      _createdAt : {
          '$date' : '2014-04-19T12:19:01.754Z'
      },
      _id : '535269b5e4b0e44dd0271627',
      _updatedAt : {
          '$date' : '2014-04-19T12:19:39.653Z'
      },
      acl : {
          '52194f94e4b0899403cbf411' : [ Object ],
          '' : [ Object ]
      },
      available : true,
      category1 : 'Pasta',
      description : 'Lovely blah',
      entity_code : 'stef1',
      name : 'Blah',
      price : 20,
      productlist_code : 'A',
      sort_order : 5
  }]
  </code></pre>