Because in the console it indicates an arrangement of 3 objects, but when displaying its information, it only has 2 objects?


I have this situation: in this image I print an arrangement that as you will see it says 3 objects but when displaying its information it only has 2 objects and when crossing it effectively it returns the information of 3 objects. Which may be?

asked by JG_GJ 10.10.2018 в 00:38

2 answers


According to what has been posted by zerocool , there is an inconsistency when printing objects (such as arrays) at the time of printing; it prints the instance of the object but at the moment of scanning that object in console (click on the arrow to see the properties of the object) it turns out that the browser is going to search again for the object showing the final state of the object, saying this if you want to know the value of your object at the moment you printed it you can do it in the following way:

let persona = { nombre: 'Nombre', edad: 20 };
// imprimir el objeto como string
// hacer un deep clone del objeto e imprimirlo
answered by 10.10.2018 / 17:15

It happened to me once before and I gave an answer in stackoverflow in English, I leave the link: inconsistencies in developer console

In the thread that I indicate in the link, the user Elliot B. explains that having a script in which he has an array and that is then modified, example:

var greetings=['hi','bye'];

If you execute it and open the development console you will see that the array with two objects will be displayed, which would be the correct thing since the console.log instruction is found before the modification of it. Now, if you run again or better, reload the page with the development console closed and after the script is finished you open it in this case that the array with 3 objects is displayed.

In his explanation leaves a link to the test jsfiddle to reproduce the case: jsfiddle play case developer console inconsistency

The same user Elliot B. is the one who comes up with the answer when he finds out that it is a bug reported for chrome: Bug 35801 chrome which indicates that it has been closed but for some reason still does not reach the release version of this browser.

The answer is that chrome shows the current state of the object when you open the debug console. Please read the answer of LPZadkiel in which you will find a solution to this error.


answered by 10.10.2018 в 16:48