Search code examples
javascriptgoogle-chrome-devtoolschildren

NodeList has 3 elements but behaves like it has 2 elements


I'm having the weirdest output where the debugger says the Node has 2 children when it has 3. Even the in the image I post here I see some incongruences, where it says the length of the object is 3 but for some reason, it prints that the length is 2.

enter image description here

Has anyone encountered this behaviour ?

Thanks for your help


Solution

  • Here's what is likely happening:

    When you log the NodeList to the console it has 2 elements, but in the moment you expand the preview, it has 3 elements. The same effect can be observed, when you add an item to an array after a certain timeout:

    console.log() changes the view live, so whenever the item changes you can see it when expanding it