Ajeet  Sinha Ajeet Sinha - 7 months ago 11
Javascript Question

How to get name of objects in global namespace in javascript

I am experiencing a javascript bug in internet explorer and I suspect its due to a name of a div matching with a global object.

My application loads many javascript libraries.

I want to find what global objects are loaded at runtime


Since all user JS defined global objects/vars are properties of the window object, you can list all the enumerable ones with this:

for (var item in window) {

This will get you a list of a lot of things including all global functions. If you want to filter out global functions, you can use this:

for (var item in window) {
    var type = typeof window[item];
    if (type != "function") {
        console.log(item + " (" + type + ")");