Pops wrote:
Now that getting a handle on the JS/jQuery language, I have these
basic questions
1) For an JSON object, how do you get the key name?
Example
var json = {field1: "data2", field2: "data2"};
I know how to get the data, but how do you get the field names? IOW, I
want to get the names of the keys.
Is there a method that traverses the JSON and returns key/value?
Do I need regex() or is there a more direct method?
I'm going to answer the first question (low hanging fruit)...
Yes, there is a direct method, just use a for loop:
for (var key in json) {
console.log(key); // key
console.log(json[key]); // value
}
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Statements:for...in
Maybe I didn't get the question right?
--Klaus