title: Detect if an Object has children in JavaScript
body: <p>In JavaScript you can get the children of an XML node like this...</p>
  
  <pre><code>var children = xml.childeNodes;
  </code></pre>
  
  <p>How do I get the children of an object?</p>
  
  <pre><code>var obj = {
    prop1: 'stuff',
    prop2: 'things',
    prop3: 'stuff-n-things'
  }
  </code></pre>
  
  <hr>
  
  <h2>Round two</h2>
  
  <p>Given an object like so..</p>
  
  <pre><code>var Obj = {
    levelOneProp1: 'stuff',
    levelOneProp2: 'things',
    levelOneProp3: {
       levelTwoProp1: 'moreStuff',
       levelTwoProp2: 'morethings',
       levelTwoProp3: 'morestuff-n-things'
    } 
  }
  </code></pre>
  
  <p>I would like to know which properties in <code>Obj</code> have children so I can loop through them in a recursive manner.  The goal is to be able to supply a dataset with an (theoretically) unlimited number of children and apply their values to input elements... Here is what I have so far.</p>
  
  <pre><code>function applyData( dataSet ){
      var hasChildren = false;
  
      for(var i = 0; i &lt; dataSet.childNodeArrayGoesHere.length; i++){
          if(dataSet.detectChildNodesHere){
              hasChildren = true;
          }
      }
  
      if(hasChildren){
          for(var j = 0; j &lt; dataSet.childNodeArrayGoesHere.length; i++){
              applyData(dataSet[j]);
          }
      } else {
          //apply the key/value pair to an input element
  
          $("input[name" + dataSet.propertyName + "]").val(dataSet.propertyValue);
      }
  }
  </code></pre>