I need to dynamically extract the key value of a JSON file and use it as a parameter in a function later. In the example below, I want to derive the first key from the JSON (firstname) and then use that to get "Bob" to return. The snippet below contains the rough idea of what works and what doesn't. I won't know that firstname is the key value until the json file has already been generated so I would really like to get the last line to work.
Even though the console logs "firstname" for my variable fName, when I use fName later it returns undefined.
var person = [];
person = [{'firstname' : 'John', 'lastname': 'Doe'},{'firstname': 'Bob', 'lastname': 'Smith'}]
var kPeeps = Object.keys(person[1]);
var fName = kPeeps[0];
console.log(kPeeps); // Keys of person - returns firstname, lastname
console.log(fName); // Item 1 in the array of Keys - returns firstname
console.log(person[1].firstname); //Works - Returns Bob
console.log(person[1].fName); //Not so much - Returns Undefined