Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6914497
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:21:17+00:00 2026-05-27T09:21:17+00:00

I have a json-object in JavaScript and I want to get the used keys

  • 0

I have a json-object in JavaScript and I want to get the used keys in it. My JavaScript-Code looks like this:

var jsonData = [{"person":"me","age":"30"},{"person":"you","age":"25"}];

And I want a loop that alerts me ‘person’ and ‘age’, which are the keys of the first object in the json-Array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:21:18+00:00Added an answer on May 27, 2026 at 9:21 am

    [What you have is just an object, not a “json-object”. JSON is a textual notation. What you’ve quoted is JavaScript code using an array initializer and an object initializer (aka, “object literal syntax”).]

    If you can rely on having ECMAScript5 features available, you can use the Object.keys function to get an array of the keys (property names) in an object. All modern browsers have Object.keys (including IE9+).

    Object.keys(jsonData).forEach(function(key) {
        var value = jsonData[key];
        // ...
    });
    

    The rest of this answer was written in 2011. In today’s world, A) You don’t need to polyfill this unless you need to support IE8 or earlier (!), and B) If you did, you wouldn’t do it with a one-off you wrote yourself or grabbed from an SO answer (and probably shouldn’t have in 2011, either). You’d use a curated polyfill, possibly from es5-shim or via a transpiler like Babel that can be configured to include polyfills (which may come from es5-shim).

    Here’s the rest of the answer from 2011:

    Note that older browsers won’t have it. If not, this is one of the ones you can supply yourself:

    if (typeof Object.keys !== "function") {
        (function() {
            var hasOwn = Object.prototype.hasOwnProperty;
            Object.keys = Object_keys;
            function Object_keys(obj) {
                var keys = [], name;
                for (name in obj) {
                    if (hasOwn.call(obj, name)) {
                        keys.push(name);
                    }
                }
                return keys;
            }
        })();
    }
    

    That uses a for..in loop (more info here) to loop through all of the property names the object has, and uses Object.prototype.hasOwnProperty to check that the property is owned directly by the object rather than being inherited.

    (I could have done it without the self-executing function, but I prefer my functions to have names, and to be compatible with IE you can’t use named function expressions [well, not without great care]. So the self-executing function is there to avoid having the function declaration create a global symbol.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an object in Javascript that looks like this function MyObject(){ this.name=; this.id=0;
I want to access the Facebook Graph API and get JSON responses like this:
I have a json output array like this { data: [ { name: Ben
I want to convert the html tag objects to json object in the javascript
I have a generic JSON structure I want to put in to a JavaScript
So, I have a json file and I want to get the names of
I have some JSON data that I get from a server. In my JavaScript,
I have a response object which I want to convert to Json, but somehow
I have the following javascript code: var groupArray = []; groupArray.push($(#group).val()); var sendInfo =
I want to encode a Javascript object into a JSON string and I am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.