2

Got a wierd problem. I console.log an object. As you can see in the picture, on object is undefined but when i flip it out you can see it have an array.

If i console.log obj.matchcvs i get undefined

enter image description here

How can this be? Bug in chrome dev tools?

Déjà vu
  • 28,223
  • 6
  • 72
  • 100
Joe
  • 4,274
  • 32
  • 95
  • 175
  • 2
    Could it be that between the time of the `log` and the click to expand, the value has been set? (since values already displayed are not refreshed in real-time) – Déjà vu Oct 08 '16 at 15:20
  • 2
    http://stackoverflow.com/questions/7389069/console-log-object-at-current-state – adeneo Oct 08 '16 at 15:22

1 Answers1

3

When you click on object in dev tools and "opens" it chrome displays it's current state. But when the object is shown in "short" version, only snapshot version of object is displayed that was created when the console.log function was called.

(function(){
  var a = { x: 0 };
  // Log variable "a", current snapshot is saved
  console.log(a);

  // Now modify the variable
  a.x = 1;
})()

Try to run this code in your dev tools, you will see that "short" version displays object with property x set to 0, when you opens it, property x is set to 1. That is because when the snapshot was created, property x was set to 0.

Buksy
  • 11,571
  • 9
  • 62
  • 69