简体   繁体   English

如何在数组内 console.log() 重复?

[英]how to console.log() duplicates inside arrays?

why does this for loop print a , o one time only, when lst_ has two a and two o ?lst_有两个a和两个o时,为什么这个 for 循环只打印a , o一次? how to fix , solve this to show all the items如何修复,解决此问题以显示所有项目

if you use console.log(x);如果你使用console.log(x); then you can see each one in the console, when this line is commented the console has only a,i,o each one a single time然后你可以在控制台中看到每一个,当这一行被注释时,控制台只有一个,i,o 每一个一次

 var lst_ = [ "a", "a", "i", "o", "o" ]; var x ; for (x =0; x < lst_.length ; x++) { console.log(lst_[x]); // console.log(x); }

Look at the console closely.仔细看看控制台。 You'll see there is a number in a blob to the left of the message.您会看到消息左侧的 blob 中有一个数字。

This means that there were that number of identical, sequential messages logged to the console.这意味着有大量相同的、连续的消息记录到控制台。

They just aren't shown one-by-one to avoid flooding the console (which becomes an issue when, for instance, you have something being logged every second) and obscuring other messages.它们只是不一一显示以避免淹没控制台(例如,当您每秒记录一些内容时,这就会成为一个问题)并隐藏其他消息。

控制台截图

You can turn "group similar" off in the console settings.您可以在控制台设置中关闭“组相似”。

控制台设置的屏幕截图

If same values occurs again, the console will indicate it with a number as follows.如果再次出现相同的值,控制台将用数字表示如下。 In your case the 'a' prints 2 times in sequence, so it shows 2 in right side.在您的情况下,“a”按顺序打印 2 次,因此它在右侧显示 2。 在此处输入图片说明

in the right of your console, you see a number.在控制台的右侧,您会看到一个数字。 This number represents the times the same line would have been printed.这个数字代表同一行被打印的次数。 If you would change the order of your array, eg like this: [ "a", "i", "o", "a", "o" ] , you should see every line如果您要更改数组的顺序,例如像这样: [ "a", "i", "o", "a", "o" ] ,您应该看到每一行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM