简体   繁体   English

Chrome控制台日志记录-Javascript

[英]Chrome console logging - Javascript

I'm wondering, why do some elements appear like an array and others like HTMLSpanElement. 我想知道为什么某些元素看起来像数组,而其他元素看起来像HTMLSpanElement。 I've attached a picture as I'm not sure how to describe this otherwise. 我附上了一张图片,因为我不确定该如何描述。

The following log is made via 通过以下日志

log(returner);
log(returner[0]);

控制台记录

Is returner a jQuery object as a result of $() ? 返回器是$()结果的jQuery对象吗? $() will always return an array, even if there is one or zero elements inside of it. $()将始终返回一个数组,即使其中包含一个或零个元素也是如此。 Without specifying an index in your first console.log, the entire contents of the array are outputted. 在第一个console.log中没有指定索引的情况下,将输出数组的全部内容。 In the second console.log, you include an array index, so only the element matching that index is outputted. 在第二个console.log中,您包括一个数组索引,因此仅输出与该索引匹配的元素。

Because the element that appears like an array IS an array - it's an array of DOM element objects (HTMLSpanElement, etc). 因为看起来像数组的元素是一个数组-它是DOM元素对象(HTMLSpanElement等)的数组。

When you log the first element of the array with returner[0] , that element is a DOM object, so it logs it as an object. 当您使用returner[0]记录数组的第一个元素时,该元素是DOM对象,因此它将其记录为对象。

因为(看起来) returner不是元素,而是元素数组。

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

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