We help IT Professionals succeed at work.
Get Started

Deterimne Javascript Object Field Names

gdpotter
gdpotter asked
on
807 Views
Last Modified: 2013-11-08
I have a project I am working on which loads in a JSON file.  I quickly convert that JSON file to a Javascript object using jquery with $.parseJSON();.  What I need to do now is to spit out what the field names are.  For example, if my data is this:
[
{
field1 : 'field1data',
field2 : 'field2data',
field4 : 'field4data'
},
{
field1 : 'field1data',
field3 : 'field3data',
field4 : 'field4data'
}
]

Open in new window


I want to take the field names and load them into an array.  The result in my example would be ['field1', 'field2', 'field3', 'field4'].  I need it to get ALL of them, even if they don't appear in every object.

If possible, I would like to do this without parsing the whole file.  Is there a way I can do this using JavaScript (and maybe jQuery) methods?

Thanks!
Comment
Watch Question
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2020
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE