title: Print out Javascript array in table
body: <p>I have this array:</p>
  
  <pre><code>var employees = [
  { "firstName":"John" , "lastName":"Doe" }, 
  { "firstName":"Anna" , "lastName":"Smith" }, 
  { "firstName":"Peter" , "lastName": "Jones" }
  ];
  </code></pre>
  
  <p>and I would like to print the entire array out as a html table. How would I accomplish this?</p>
  
  <p>I tried this but could only get the final name the print:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;h2&gt;Create Object from JSON String&lt;/h2&gt;
  &lt;p&gt;
  First Name: &lt;span id="fname"&gt;&lt;/span&gt;&lt;br /&gt; 
  Last Name: &lt;span id="lname"&gt;&lt;/span&gt;&lt;br /&gt; 
  &lt;/p&gt; 
  &lt;script type="text/javascript"&gt;
  var txt = '{"employees":[' +
  '{"firstName":"John","lastName":"Doe" },' +
  '{"firstName":"Anna","lastName":"Smith" },' +
  '{"firstName":"Peter","lastName":"Jones" }]}';
  
  var obj = eval ("(" + txt + ")");
  
  for (i=0; i&lt;txt.length; i++){
      document.getElementById("fname").innerHTML=obj.employees[i].firstName 
      document.getElementById("lname").innerHTML=obj.employees[i].lastName 
  }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>