How can I make console.log show the current state of an object?

前端 未结 11 1784
走了就别回头了
走了就别回头了 2020-11-22 00:28

In Safari with no add-ons (and actually most other browsers), console.log will show the object at the last state of execution, not at the state when conso

11条回答
  •  时光说笑
    2020-11-22 01:21

    I think you're looking for console.dir().

    console.log() doesn't do what you want because it prints a reference to the object, and by the time you pop it open, it's changed. console.dir prints a directory of the properties in the object at the time you call it.

    The JSON idea below is a good one; you could even go on to parse the JSON string and get a browsable object like what .dir() would give you:

    console.log(JSON.parse(JSON.stringify(obj)));

提交回复
热议问题