I have an issue with displaying data of an associative array in a table. Here is my code:
$.getJSON('json/data.json', function(data){
var items=[];
$.each(data, function(key, val){
$.each(val, function(keyItem, valItem){
items.push('<td>'+valItem+'</td>');
});
$('<tr/>', {html: items.join('')}).appendTo('.table tbody');
});
});
Here is my array:
[
{
"firstName": "Mike",
"lastName": "Winston",
"sex": "male",
"age": "28"
},
{
"firstName": "Mikki",
"lastName": "Grathem",
"sex": "female",
"age": "21"
},
{
"firstName": "Nick",
"lastName": "Malboro",
"sex": "male",
"age": "31"
}
]
I need that the data of the array is displayed in a new line of the table. Now I have such situation:

Where is a mistake?