When I do
for (var i in window) console.log(window[i])
I get a list of window properties and methods
Howver when I do the same for "Math" object, I get nothing.
typeof "window" == typeof "Math"
returns TRUE, so I do not see a reason why my loop is not working.
It’s strange as if I write directly Math['E'] I get the value of constant E.
Not all object properties are iterable. You’ll only get iterable properties in a
for..inloop.Since most properties of
window(which happens to be the global object) are user-defined global variables, they are enumerable.In modern JavaScript engines you can use
Object.getOwnPropertyNames(obj)to get all properties, both enumerable and non-enumberable:See Is it possible to get the non-enumerable inherited property names of an object? for more details.