Here I'm looping through an object and retrieving the key:value pairs and placing them in a table
obj = clickedRecord.toJSON(); //gets record from
//separate table and converts to JSON format
var array=[];
for(key in obj) {
if(obj.hasOwnProperty(key)) {
array.push(
'<table id="myTable">' +
'<tr>' +
'<td>' + key + '</td>' +
'<td>' + obj[key] + '</td>' +
'<tr>' +
'</table>''
);
}
}
The output of which is:
ID 100
,
Name Billy
,
Address 525 Park Lane
,
Is there a cleaner way to dynamically construct a table using a javascript Object, as well as omit the commas from the returned data?
.join('')to the end of the output expression.