I have two types of arrays,
var arr1 = ["mike", "john"];
var arr2 = [{
dan: {name: "dan brown", occupation: "police officer", age: 25},
john: {name: "john blake", occupation: "student", age: 20},
mike: {name: "mike floss", occupation: "student", age: 19}
}];
I have displayed the tablebody using the following code.
function loopArray(arr1, arr2) {
$.each(arr1, function(i) {
var templateString = '<table id="partstable" class="table table-hover"><tbody><tr><td class="name">'
+ arr2[arr1[i]].name + '</td><td>'
+ arr2[arr1[i]].occupation + '</td><td>'
+ arr2[arr1[i]].age + '</td>';
$('#test').append(templateString);
})
}
and calling this function.
This is the output I have gotten.
I would like to find out whether there is a way to add headers name, occupation and age to the table and whether there is a better way to output a table in general. Thank you for your help.

Nodeelements instead of treating the HTML as plain strings. This allows you to do things like insert nodes into other nodes by appending or prepending.