使用JavaScript对象的console.log的奇怪行为 [英] Weird behaviour of console.log with JavaScript object

查看:136
本文介绍了使用JavaScript对象的console.log的奇怪行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用HTML为每个循环打印对象时,我只得到对象的一半内容但是当我使用 console.log 打印时按下那个小三角形我当我在悬停时显示完整对象和 i ,它表示刚刚评估了值,如下图所示,

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,

当我在html中打印相同的对象时,它看起来像这样,

When i print same object in html it looks like this,

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

实际上对象包含总共5个元素,如上图所示,
代码用于打印对象html,

Actually object contains total 5 elements as shown in above image, Code for printing object html,

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


推荐答案

通过<$ c检查对象$ c> console.log 以异步方式发生。

对象的引用同步传递给控制台,但在扩展之前它不会显示属性。如果在控制台中检查对象之前修改了对象,则显示的数据将具有更新的值。 Chrome控制台在一个框中显示一点 i ,其中表示刚刚评估了以下值

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));

这篇关于使用JavaScript对象的console.log的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆