Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8402015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:56:48+00:00 2026-06-09T21:56:48+00:00

I have this array: var employees = [ { firstName:John , lastName:Doe }, {

  • 0

I have this array:

var employees = [
{ "firstName":"John" , "lastName":"Doe" }, 
{ "firstName":"Anna" , "lastName":"Smith" }, 
{ "firstName":"Peter" , "lastName": "Jones" }
];

and I would like to print the entire array out as a html table. How would I accomplish this?

I tried this but could only get the final name the print:

<!DOCTYPE html>
<html>
<body>
<h2>Create Object from JSON String</h2>
<p>
First Name: <span id="fname"></span><br /> 
Last Name: <span id="lname"></span><br /> 
</p> 
<script type="text/javascript">
var txt = '{"employees":[' +
'{"firstName":"John","lastName":"Doe" },' +
'{"firstName":"Anna","lastName":"Smith" },' +
'{"firstName":"Peter","lastName":"Jones" }]}';

var obj = eval ("(" + txt + ")");

for (i=0; i<txt.length; i++){
    document.getElementById("fname").innerHTML=obj.employees[i].firstName 
    document.getElementById("lname").innerHTML=obj.employees[i].lastName 
}
</script>
</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T21:56:49+00:00Added an answer on June 9, 2026 at 9:56 pm

    Using jQuery you can do:

    var txt = '{"employees":[' +
        '{"firstName":"John","lastName":"Doe" },' +
        '{"firstName":"Anna","lastName":"Smith" },' +
        '{"firstName":"Peter","lastName":"Jones" }]}';
    
    // $.parseJSON will parse the txt (JSON) and convert it to an
    // JavaScript object. After its call, it gets the employees property
    // and sets it to the employees variable
    var employees = $.parseJSON( txt ).employees;
    
    var $table = $( "<table></table>" );
    
    for ( var i = 0; i < employees.length; i++ ) {
        var emp = employees[i];
        var $line = $( "<tr></tr>" );
        $line.append( $( "<td></td>" ).html( emp.firstName ) );
        $line.append( $( "<td></td>" ).html( emp.lastName ) );
        $table.append( $line );
    }
    
    $table.appendTo( document.body );
    
    // if you want to insert this table in a div with id attribute 
    // set as "myDiv", you can do this:
    $table.appendTo( $( "#myDiv" ) );
    

    jsFiddle: http://jsfiddle.net/davidbuzatto/aDX7E/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array like this var array = [{ order: 3, sub -
I have an associative array which when var dumped looks like this: Array (
I have an array like this: var arr1 = [a, b, c, d]; How
I have javascript code some thing like this -- var count=3; var pl=new Array(count);
I have an array of objects, like this: var companies = [ { name
I have like this: var array = [name1,imagesrc1,name2,imagesrc2,name3,imagesrc3,...]; I print the images but I
I have this string of numbers var array = 1,6,2,9,5 which is retrieved from
Let's say I have this $(document).ready(function() { var array = $.makeArray($('p')); $(array).appendTo(document.body); }); });
I have this code: var a:Array = [ Ramsey, Tusey, Iuser,Sephora,'user', 'reseo', 'nesey', 'sela']
i have this JSON: var projects_array = new Array( {name:myName1, id:myid1, index:1}, {name:myName2, id:myid2,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.