Strange consolelog behavior with JavaScript object

When I print an object in HTML using for each loop, I only get half the content of the object, but when I print with console.log

and console.log

this little triangle, I get the full object, and I show next to that object, when I hover it says the value was only evaluated now as shown in the picture below,enter image description here

When I print the same entity in HTML it looks like this,

7.33--AAYUSH MOHTA
7.08--AAYUSH PRAKASH
7.83--ABHINAV KUMAR TIWARI

      

Actually object

contains only 5 elements as shown in the image above, the code to print the HTML entity,

 for (var key in obj){
        $("p").append(key+"--"+obj[key][0]+"<br>");
    }

      

+3


source to share


1 answer


The study of objects through is console.log

done with asynchronous

.

The object reference is passed synchronously to the console, but it does not display properties until it is expanded. If the object has changed before viewing it in the console, the data shown will have the updated values. Chrome console shows a bit i

in a box that says the value below was only evaluated now



To completely print an object to the console, you can strict and register it like

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

      

+8


source







All Articles