9

What I loved about Python was that if you wanted to know something about a particular module, you could just go something like this:

dir(django.auth.models)

and it would give you all the things inside of models, is there something similar to this in JavaScript?

Games Brainiac
  • 80,178
  • 33
  • 141
  • 199

3 Answers3

12

You could use Object.keys(), e.g.:

> Object.keys(window)
["top", "window", "location", "external", "chrome", "Intl", "v8Intl", "document", "$", "jQuery", "MSIsPlayback", "i", "prepareEditor", "StackExchange", "scriptSrc", "careers_adurl", "careers_cssurl", "careers_leaderboardcssurl", "careers_companycssurl", "careers_adselector", "_gaq", "_qevents", "jQuery171008060155878774822", "__qc", "quantserve", "uh", "_gat", "gaGlobal", "gauth", "genuwine", "moveScroller", "styleCode", "sanitizeAndSplitTags", "initTagRenderer", "showFadingHelpText", "initFadingHelpText", "profileLink", "EventEmitter", "votesCast", "tagRendererRaw", "tagRenderer", "ytCinema", "IN_GLOBAL_SCOPE", "prettyPrintOne", "prettyPrint", "PR_SHOULD_USE_CONTINUATION", "PR", "Markdown", "apiCallbacks"]
NPE
  • 486,780
  • 108
  • 951
  • 1,012
  • 1
    Although `Object.keys()` behaves like `dir()` in that it returns they keys without values, it is much more common to use `console.log()`. – Luqmaan Jun 29 '13 at 14:33
2

I don´t know if doesn´t have this option in 2013, but today we have:

console.dir(variable)

ps: This answer is for those fall here after a googling 'python dir in javascript' (like me! by the way).

Paulo Vinícius
  • 326
  • 2
  • 9
1

If you do console.log(variable) in javascript, you'll see information about that variable in your browser's debugging console. If the variable is an object for example, you'll see it's attributes.

gitaarik
  • 42,736
  • 12
  • 98
  • 105