title: Javascript/Jquery push json objects into array
body: <p>I have an json object coming from a <code>$.post</code> in jquery.
  In order to loop through and store the data clientside I would like to add it to an array. For each search results that comes back I would like to "append" the array so it grows.</p>
  
  <p>This is my json:</p>
  
  <pre><code>    {
  "companies": [
  {
    "companyid": "115",
    "saved": false,
    "orgnumber": "010101010",
    "companyname": "TestCompany",
    "header": "header info"
    },      
    {
    "companyid": "116",
    "saved": false,
    "orgnumber": "010101010",
    "companyname": "TestCompany",
    "header": "header info"
    } ]
        }
  </code></pre>
  
  <p>This is what I have come up with so far were data is the json 
  comming back fron the post ajax request. Obj is just an object holding the array
  which I declared further up in my code. obj.companies = new Array();</p>
  
  <pre><code>   obj.companies.push(data['companies']);
  </code></pre>
  
  <p>The next part I need to loop out the array. Trying to do it like this.</p>
  
  <pre><code>     $.each(obj.companies, function(i, item) {      
  
         // Does not alert correctly.
         alert(item.header);
  
       });
  </code></pre>
  
  <p>So I need to push the full json object into the array. But I cannot alert the item.header within the loop, how can I accomplish this?</p>
  
  <p>EDIT:
  Thanks everyone. Sorry if my question wasnt detailed enough.
  I ended up doing this:</p>
  
  <pre><code>        getcompanies: function() {
            obj = this;
            $.post('api/finder/result.php', {}, function(data) {
                  $.each(data.companies, function(i, item) {      
                      obj.companies.push(item);
                  });             
                  obj.loadcompanies();                        
            }, "json");
         },
  
  
          loadcompanies: function() {
             $.each(this.companies, function(i, item) {       
               alert(item.header);
            }
          }
  </code></pre>