I am unable to iterate the following JSON as I am expecting. The code is given as below :
$(document).ready(function() {
var data = '{"employees":\n\
[{"908887" : {"firstName":"John", "lastName":"Doe"}},\n\
{"98764" : {"firstName":"Anna", "lastName":"Smith"}},\n\
{ "98762" : {"firstName":"Peter", "lastName":"Jones"}}]}';
var empObj = JSON.parse(data);
for(var key in empObj.employees){
alert('key - ' + key + ' value - ' + empObj.employees[key]);
}
});
In alert, I am getting the keys 0, 1, 2, but I want: 908887, 98764, 98762. I also want to iterate over the values.
Please tell how to solve the issue.