JavaScript Array`console.log`输出行为

时间:2017-07-03 07:01:49

标签: javascript console console.log

当我们在数组上运行forEach()函数时,取决于index&的方式。 items安排dev工具返回不同的输出。我想知道是否有人知道为什么会这样。

请参阅以下图片:

enter image description here

当我将变量从item, index交换到index, item时,输出看起来不同。

enter image description here

我想知道是什么让变量输出不同以及为什么。

2 个答案:

答案 0 :(得分:1)

根据有关console.log here

的MDN文档

这解释了第一个参数作为对象或字符串处理。后续参数作为对象处理。

假设这会强制字符串从第二个参数开始,用引号打印。

要了解有关Chrome控制台的更多信息,请访问this page

答案 1 :(得分:0)

正如here所说

Syntax
console.log(obj1 [, obj2, ..., objN]);
console.log(msg [, subst1, ..., substN]);
Parameters

obj1 ... objN
A list of JavaScript objects to output. The string representations of each of these objects are appended together in the order listed and
     

输出

当你编写consoloe.log(项目,索引)时,它首先写项目然后索引,反之亦然