Object inspector for JavaScript

Sometimes, one cannot inspect JavaScript-objects using an external debugger, like Firebug.

For example, this can happen during development of Firefox addons: Open the JavaScript inspector of Firebug and you will only see the JavaScript errors on the currently displayed website, but not the ones from the addon.

Thus, I modified the inspect()-function from Ariel Tapia (codeprojects.com) a bit. My version will not only return a HTML string with all the attributes and functions that are inside the object. It will also add the values of these.

Installation: Just unzip the file and include it via
<script src="inspector.js" type="text/javascript"></script>
(As an alternative, you can also just copy and paste the function directly into your source.)

Example usage: var htmlResult = inspect(myObject, null, null);
htmlResult will now hold a string-representation of the properties and functions of myObject.

Note: An alternative for Firefox addons is Venkman. Haven’t really figured out how to use that though.
So, if you don’t want to bother with Venkman or need an object-inspector for any other purpose, I think you’ll be fine with my function provided above.

Follow me on social media

One thought on “Object inspector for JavaScript

  1. Thank you,

    I’ve written a simpler function:

    function objInsp(obj) {
    var html = ‘<ul>’;
    for (var i in obj) {
    html += ‘<li>’ + i + ‘ : ‘ + ((‘object’ == typeof obj[i]) ? objInsp(obj[i]) : obj[i]) + ‘</li>’;
    html += ‘</ul>’;
    return html;

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.