title: How to do a each inside a each in jquery?
body: <p>I have this json object :</p>
  
  <pre><code>{
  "msg_id":"134",
  "message":"Dick",
  "comment":[
      {
      "com_id":"9",
      "comment":"test",
      "msg_id":"134",
      },
      {
      "com_id":"10",
      "comment":"testtt",
      "msg_id":"134",
      },
      {
      "com_id":"11",
      "comment":"testtttt",
      "msg_id":"134",
      }]
  },
  {
  "msg_id":"134",
  "message":"Dick",
  },
  {
  "msg_id":"134",
  "message":"Dick",
  }
  </code></pre>
  
  <p>And I'm trying to iterate through it twice. Once for the main json object and then for the <code>comment</code> one.</p>
  
  <p>I tried this:</p>
  
  <pre><code>$.each(data, function(index, obj){
      msg += template.replace( /{{message}}/ig  , obj.message )
                     .replace( /{{msg_id}}/ig   , obj.msg_id );
  
      $.each(obj.comment, function(key, val){
              msg += template.replace( /{{comment}}/ig , val.comment )
                     .replace( /{{com_id}}/ig , val.com_id )
                     .replace( /{{msg_id}}/ig , val.msg_id );           
      });   
  });
  </code></pre>
  
  <p>If I do this I get <code>a is undefined jquery.js line 2</code>. Maybe I need to create another function for the second loop.</p>