As this is an javascript object you can use jQuery's $.each() method to get the key names:
success: function(data) { $.each(data, function(key, item){ console.log(key); // this gets you the key names }); }
As per your comment
how would i assign key 2 to a variable without using its name?
var o = { "normalkey": "John Smith", "dynamickey ": "testing" }; var a = []; // declare an empty array. $.each(o, function(key, item){ a.push(key); // push the keys in it. }); var dynkey = a.pop(); // .pop() gets you the dynamickey here as // this is the last item in the array. console.log(dynkey); // this logs = dynamickey
Description about .pop() @ MDN Docs:
The pop method removes the last element from an array and returns that value to the caller.
So with your last comment:
success: function(data) { var a = []; $.each(data, function(key, item){ a.push(key); // this gets you the key names }); var dynkey = a.pop(); $('#container').html(data[dynkey]); // <----here you have to do this. }