I would like to display the current values of an object's attributes in Javascript.
I did a console.log(object)
and it gave me this :
And it gave me an i
blue box that when hovered, it gives me this text object value at left was snapshotted when logged, value below was evaluated just now.
I saw a few previous posts suggesting to convert the log to JSON using console.log(JSON.parse(JSON.stringify(object)));
but it just gives me the values in red.
I am more interested in the ones in green.
This actually brings a question : Which of these values are the latest, eventually final ? The ones in red or the ones in green ?
Thanks!
The green values are the values as they were when you expanded the log.
The red values are the values from the time you logged them.
A simple test in the console
let obj2 = { a: 1, b: 2, c:3, d:4, e:5, f:6 };
setInterval(()=>{
obj2.a+=0.1;
obj2.b+=0.01;
});
console.log(obj2);
Provides this capturing image when I expand the logged object
No matter how many times I expand again the values remain and if I want the updated values I need to do another console.log(ob2)
.
The values in the red box are values when the console.log
was called. Green ones are the values after the Object in your console was clicked. If you have a loop, then calling console.log
each time in end of the loop will give you the latest values always. If you want only the final value, then after your loop or calculations have ended and the values wont be modified again, call console.log
on the object and it will give you the final values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With