I have a simple JSON object, but the problem is that the key can change which means I can't call the data with its key name. My aim is to present the data in a table layout.
This is one example of how I get the data:
[{"domain":"animals","country":"Argentina"}]
But it can also be that I get this result
[{"fruits":"apple","country":"Argentina", "value": "1234"}]
Now I could find out how to get the keys:
var dataKeys = []
for( var key in data[ 0 ] ) {
dataKeys.push( key );
console.log(key);
}
Very well, now I have the names for the columns. But from here I have no clue how to get the values to each key.
var dataKeys = []
for( var key in data[ 0 ] ) {
dataKeys.push( key );
//console.log(key);
}
//console.log(result.join());
for( var x in data ) {
for (var i in dataKeys) {
console.log(data[dataKeys[i]]);
};
}
But the console shows "undefined".