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
Add a ment  | 

1 Answer 1

Reset to default 3

That'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