View list of all JavaScript variables in Google Chrome Console

后端 未结 15 2057
星月不相逢
星月不相逢 2020-11-29 14:32

In Firebug, the DOM tab shows a list of all your public variables and objects. In Chrome\'s console you have to type the name of the public variable or object you want to ex

相关标签:
15条回答
  • 2020-11-29 15:05

    List the variable and their values

    for(var b in window) { if(window.hasOwnProperty(b)) console.log(b+" = "+window[b]); }
    

    Display the value of a particular variable object

    console.log(JSON.stringify(content_of_some_variable_object))
    

    Sources: comment from @northern-bradley and answer from @nick-craver

    0 讨论(0)
  • 2020-11-29 15:06

    Try this simple command:

    console.log(window)
    0 讨论(0)
  • 2020-11-29 15:08

    The window object contains all the public variables, so you can type it in the console and then expand to view all variables/attributes/functions.

    chrome-show-all-variables-expand-window-object

    0 讨论(0)
  • 2020-11-29 15:10

    enter image description here

    0 讨论(0)
  • 2020-11-29 15:11

    Open the console and then enter:

    • keys(window) to see variables
    • dir(window) to see objects
    0 讨论(0)
  • 2020-11-29 15:15

    As all "public variables" are in fact properties of the window object (of the window/tab you are looking at), you can just inspect the "window" object instead. If you have multiple frames, you will have to select the correct window object (like in Firebug) anyway.

    0 讨论(0)
提交回复
热议问题