最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Display current object value console log - Stack Overflow

programmeradmin5浏览0评论

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!

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!

Share Improve this question asked Jun 14, 2016 at 11:30 user1885868user1885868 1,0933 gold badges18 silver badges32 bronze badges 3
  • 1 green ones are the latest – Hendry Commented Jun 14, 2016 at 11:34
  • Thanks @Hendry ! Is there a way go grab them ? All I get is the ones in red – user1885868 Commented Jun 14, 2016 at 11:36
  • 1 if you want the latest values, then console log after each or after last update to the object – Hendry Commented Jun 14, 2016 at 11:39
Add a ment  | 

2 Answers 2

Reset to default 4

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.

发布评论

评论列表(0)

  1. 暂无评论