Hi I have a question about getting the names of properties of an object.
The context
I am retrieving some data from a database which I am trying to get the column headings from. I am carrying out an ajax request to get the data as JSON.
The code
var tableHeaders = "noHeaders";
var columns = [];
$( document ).ready( function( $ ) {
$.ajax({
"url": 'ajaxScripts/getDynamicData.php',
"success": function(json) {
tableHeaders = "";
parsedData = JSON.parse(json);
$.each(parsedData[0], function(i, val){
console.log(parsedData[0]);
tableHeaders += "<th>" + val + "</th>";
columns.push(val);
});
$("#headings").append(tableHeaders);
//$("#tableDiv").find("table thead tr").append(tableHeaders);
$('#demotable').DataTable({
dom: "Bfrtip",
data: parsedData,
columns: columns
});
}
});
});
Table Sample
Name | Age | DOB | Height | Weight | Address | Hair Colour | Eye Colour
Steve| 24 | 22/11/1994 ...
The data gets returned as an array of Objects so I want to be able to retrieve the unique properties of those objects - The column headers (Name, Age, DOB etc)