title: Identifying the last item in a JavaScript object or associative array
body: <p>I'm putting together some JavaScript that'll be pulling in multiple JSON files whose data will be used in graphs. Ultimately, I need to identify when I've reached the absolute end of an associative array being processed in an <code>$.each()</code> loop <em>(jQuery is involved)</em> in order to trigger the next JSON file. I've bumped into various solutions for a one-tiered object...but what about a MULTI-TIERED object? How does the last row in the last column know it's the LAST?</p>
  
  <p>Here's an example JSON I'm working with:</p>
  
  <pre><code>{
      "Network":{
          "Hardware":262464,
          "Software":53016,
          "Internal Personnel":440202,
          "External Personnel":188658,
          "Outside Services":1344100,
          "Facilities and Overhead":16172,
          "Other":92588,
          "Total":2397200
      },
      "Wide Area Network":{
          "Hardware":75600,
          "Software":18900,
          "Internal Personnel":132300,
          "External Personnel":56700,
          "Outside Services":315000,
          "Facilities and Overhead":6300,
          "Other":25200,
          "Total":630000
      }
  }
  </code></pre>
  
  <p>Here's a rough idea of a loop I'm running on that JSON</p>
  
  <pre><code>function buildColumns(array, parent) {
      $.each(array, function(key, value) {
          var newParent = $('&lt;column&gt;'); 
          $('&lt;columnBox&gt;').append($('&lt;h2&gt;').html(key)).append(newParent).appendTo(parent);
          if(value instanceof Object) buildColumns(value, newParent);     
      });
  }
  </code></pre>
  
  <p>The loop is pseudo-recursive, as you can see, and may not ultimately be what I use. But there you go.</p>