Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
128
rated 0 times [  130] [ 2]  / answers: 1 / hits: 16705  / 11 Years ago, tue, november 5, 2013, 12:00:00

I want to get the key from the JSON Array?
This is my JSON Array



****JAVASCRIPT****
var employees = [
{ firstName:John , lastName:Doe },
{ firstName:Anna , lastName:Smith },
{ firstName:Peter , lastName: Jones }
];


From this JSON I need the result key. I mean firstName, lastName, not John, Anna, Peter
Please help to get the keys from JSON.


More From » jquery

 Answers
30

Try this:



http://jsfiddle.net/NJMyD/1072/



var employees = '[{firstName:John,lastName:Doe },{firstName:Anna,lastName:Smith },{firstName:Peter,lastName:Jones}]';

var myData = JSON.parse(employees);

$(document).ready(function() {
$.each(myData, function() {
$('<li>' + this.firstName + ' ' + this.lastName + '</li>').appendTo(#groups);
});
});

[#74501] Monday, November 4, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jonrened

Total Points: 627
Total Questions: 114
Total Answers: 99

Location: Zimbabwe
Member since Thu, Jul 21, 2022
2 Years ago
jonrened questions
Mon, Nov 2, 20, 00:00, 4 Years ago
Tue, May 19, 20, 00:00, 4 Years ago
Tue, Jan 21, 20, 00:00, 4 Years ago
Thu, Nov 7, 19, 00:00, 5 Years ago
;