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

  • Home
  • SEARCH
  • 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 6021023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:39:09+00:00 2026-05-23T03:39:09+00:00

Note: I’m going to use a specific object as an example here, but please

  • 0

Note: I’m going to use a specific object as an example here, but please don’t post answers specific to this example; the question is more general.

Specific example

I wrote some jQuery code like this…

$('#some_button').click(function(event) {
    $.post('<some URL>', { <some parameters> },
        function() { <do something on success> })
        .error(function(x) {
            // What is x?
        });
    event.preventDefault();
});

Now, for the purpose of this question, let’s assume that there is no documentation about that object x that is passed in.

An obvious thing to do might be

alert(x);

but all that will output is [object Object].

General question

What might be an easy way to find out what properties/methods an unknown object has? I’m thinking something that I’d just write during the debugging phase, no production code of course.

You may assume that jQuery is available.

Edit:

I’m fully aware of for (...), but surely that doesn’t mean there can’t be a better/easier way — I thought jQuery might have something built-in…

  • 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-23T03:39:09+00:00Added an answer on May 23, 2026 at 3:39 am

    A general and single level basic javascript solution

    Basic functionality looks like this:

    var s = "";
    for(var p in obj)
    {
        s += p + " = " + obj[p] + "\n";
    }
    alert(s);
    

    Object graph issue

    It will enumerate over all properties of an object. If this particular object has deep object trees you should better put this into a function and then recall it on sub object. enumerate internal sub object using the same technique. Arrays are a similar issue.

    But I suppose you’ll be able to provide this kind of functionality from this starting example code.

    Browser console solution

    If you have development console open in your browser (in Firefox that would be Firebug) then you can easily just call this:

    console.log(obj);
    

    But there’s a problem with IE, because when it comes to a complex object is just displays {...} which isn’t really helpful. So this approach can only be used in Chrome and Firefox+Firebug.

    A jQuery plugin for any browser

    This is a small and simple plugin I’ve come up to enumerate an arbitrary object and display its content in browser’s console:

    $.extend({
        inspect: function(obj,n){
            n = n || "this";
            if ($.isArray(obj)) {
                for (var x = 0; x < obj.length; x++) {
                    $.inspect(obj[x], n + "[" + x + "]");
                }
                return;
            }
            if ($.isPlainObject(‌​obj)) {
                for (var p in obj){
                    $.inspect(obj[p], n + "." + p);
                }
                return;
            }
            console.log(n + " = " + obj.toString());
        }
    });
    

    This code works with any browser (I actually needed it for IE, because of the previously mentioned issue with {...} display.

    It parses an object graph into console provided that your browser’s console is open. In IE and Chrome that’s the built in development console and in Firefox it’s Firebug console.

    You can use it as:

    $.inspect(yourObject);
    

    or

    $.inspect(yourObject, "person");
    

    The second optional parameter is used to give your object a name when displaying it. If you don’t provide the name it will be set as "this". Your object will be displayed as:

    this.name = "John"
    this.lastname = "Doe"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about templates that can be used with parameters that are
I have multiple classes that are not allowed to modify each other's fields, but
I am coding for an Intranet. In theory, I don't have to worry too
Switching the code of the debate forum on my website, I am going to
Some of you may or may not (probably not) know about my framework .
I am using a UIScrollView to create the illusion of lined paper behind my
saving the managedObjectContext seems to eat the NSUserDefault NSString *defaultSiteUrl = [[NSUserDefaults standardUserDefaults] objectForKey:kSelectedSiteUrlKey];
I'm learning ruby on rails by following the tutorials in http://ruby.railstutorial.org/ . I'm getting
So I seem to be getting burned by the iPhone's calendar support again .
I have a query that by all rights should not possibly fail, and I

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.