title: Creating a Nested List with an Object Array
body: <p>I have a set of SQL data which will change frequently and I need to create a nested, unordered list from that on a regular basis. I have converted the SQL data into an object array, but I'm stuck on the logic for creating the unordered list from that.</p>
  
  <p>I tried making a recursive function, but I'm not experienced enough with those, so </p>
  
  <p>The data contains these fields:</p>
  
  <pre><code>ID  Category Name   ParentID
  </code></pre>
  
  <p>So, each category has an ID and a ParentID (which matches the ID of another category). Root categories all have the same dummy ParentID.</p>
  
  <p>The javascript object has the same properties. Here's an example:</p>
  
  <pre><code>var Categories = [
  new Category(1, 'Root', 0),
  new Category(2, 'Cat1', 1),
  new Category(3, 'Cat2', 2),
  new Category(4, 'Cat3', 5),
  new Category(5, 'Cat4', 1),
  new Category(6, 'Cat5', 5),
  new Category(7, 'Cat6', 5),
  new Category(8, 'Cat7', 1),
  new Category(9, 'Cat8', 2),
  new Category(10, 'Cat9', 1),
  new Category(11, 'Cat10', 10),
  new Category(12, 'Cat11', 1),
  new Category(13, 'Cat12', 8)
  ]
  </code></pre>
  
  <p>I need to use that object array to make an unordered list that would look like this:</p>
  
  <pre><code>&lt;ul&gt;
  &lt;li&gt;Cat1
      &lt;ul&gt;
          &lt;li&gt;Cat2&lt;/li&gt;
          &lt;li&gt;Cat8&lt;/li&gt;
      &lt;/ul&gt;
  
  &lt;li&gt;Cat4
      &lt;ul&gt;
          &lt;li&gt;Cat3&lt;/li&gt;
          &lt;li&gt;Cat5&lt;/li&gt;
          &lt;li&gt;Cat6&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Cat7
      &lt;ul&gt;
          &lt;li&gt;Cat12&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Cat8&lt;/li&gt;
  &lt;li&gt;Cat9
      &lt;ul&gt;
          &lt;li&gt;Cat10&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;Cat11&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Currently, the deepest my data goes is 3 tiers, but I would like to be able to have the script do any number of tiers.</p>
  
  <p>jQuery is OK for this.</p>