By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 961 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

JSON reference 'name' not 'value'

RMWChaos
100+
P: 137
Okay, this should be simple, but my simple little brain just can't quite figure it out.

If I have a JSON object like this:

Expand|Select|Wrap|Line Numbers
  1. var myJSONArray(arrayName)
  2.    {
  3.    "name1"  :  "value1",
  4.    "name2"  :  "value2
  5.    };
  6.  
I know how to reference the values: arrayName.value1, arrayName.value2. I can even iterate over the values: for (var idx in arrayName), and reference all the values: arrayName[idx].

Now how in the world do I reference the names when I don't know them? I have been looking everywhere for this answer. Say I want a simple output of "name1 is value1" and "name2 is value2"...it would be something like: arrayName[something?] + " is " + arrayName[index].

Thanks.
Oct 31 '07 #1
Share this Question
Share on Google+
1 Reply


RMWChaos
100+
P: 137
I was able to get my answer in this thread:

JSON/Array Question Thread

Basically, if...
Expand|Select|Wrap|Line Numbers
  1. for(var index in object)
  2.  
...then "index" is the name and "object[index]" is the value.
Nov 1 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.