Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value was evaluated just now with console.log on JavaScript object

When I print object in HTML using for each loop I'm getting only half contents of the object but when I print using console.log and press that little triangle I'm getting full object and i is shown near that object when I hover that it says value was evaluated just now as shown in below image, enter image description here

When I print same object in HTML it looks like this,

7.33--Some Name
7.08--Some Name
7.83--Some Name

Actually, object contains a total of 5 elements as shown in the above image, Code for printing object HTML,

for (var key in obj){
    $("p").append(key+"--"+obj[key][0]+"<br>");
}
like image 329
Mehul Prajapati Avatar asked Jun 05 '17 06:06

Mehul Prajapati


People also ask

Can you console log an object in JavaScript?

You can use the console. log() method, if you simply wants to know what's inside an object for debugging purpose. This method will print the object in browser console.

How do we log a value to the console in JavaScript?

log() is a function in JavaScript that is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Syntax: console. log(" ");

How do I check the value of console logs?

Steps to Open the Console Log in Google Chrome By default, the Inspect will open the "Elements" tab in the Developer Tools. Click on the "Console" tab which is to the right of "Elements". Now you can see the Console and any output that has been written to the Console log.


1 Answers

Examining objects via console.log happens in an asynchronous manner.

The reference to the object is passed synchronously to console but it doesn't display the properties till its expanded . If the object has been modified before examining it in the console, the data shown will have the updated values. Chrome console shows a little i in a box which which says value below was evaluated just now

In order to print the object completely in console, you can stringify and log it like

console.log(JSON.stringify(obj));
like image 186
Shubham Khatri Avatar answered Sep 20 '22 10:09

Shubham Khatri