admin管理员组文章数量:1333201
I am using Console.log to identify the array values of a function. While examining the console I see a number of places where Array(0) exists:
In particular, I have created an array of key value pairs (see "x" and "testedElements" (same object) at the bottom of the picture above.)
When I expand "x" out that "Array(0)" sits at the top of an array element... I am unsure what "Array(0) means.. does it signify that this element is an array?
I was actually trying to recreate the structure of "full MENU" at the top of the console picture but I have "Array(0)" displaying in the middle of testedElements/x...
I am using Console.log to identify the array values of a function. While examining the console I see a number of places where Array(0) exists:
In particular, I have created an array of key value pairs (see "x" and "testedElements" (same object) at the bottom of the picture above.)
When I expand "x" out that "Array(0)" sits at the top of an array element... I am unsure what "Array(0) means.. does it signify that this element is an array?
I was actually trying to recreate the structure of "full MENU" at the top of the console picture but I have "Array(0)" displaying in the middle of testedElements/x...
Share edited Jun 20, 2020 at 9:12 CommunityBot 11 silver badge asked Dec 27, 2017 at 13:11 si2030si2030 4,0458 gold badges46 silver badges96 bronze badges 2- 7 It means an array with zero length. – JJJ Commented Dec 27, 2017 at 13:12
- It is initialized as array but has an object structure. – Miquel Al. Vicens Commented Dec 27, 2017 at 13:14
1 Answer
Reset to default 3That's how Chrome displays an 0-length array in value summaries in the console. Empty arrays can still contain fields due to the nature of JavaScript.
var obj = {};
obj.array = [];
obj.array.myField = 1;
console.log(obj);
This will log the following in the console:
> {array: Array(0)}
And when I expand it:
{array: Array(0)}
array: Array(0)
myField: 1
length: 0
__proto__: Array(0)
__proto__: Object
This shows that named fields are not items in an array.
If you want an associative array (Array with named indexes), you should use plain JavaScript objects.
var obj = {};
obj.A = 10;
本文标签: JavascriptChrome ConsoleWhat does quotArray(0)quot meanStack Overflow
版权声明:本文标题:Javascript - Chrome Console - What does "Array(0)" mean? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742286432a2447012.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论