Javascript - Chrome Console - What does "Array(0)" mean? Javascript - Chrome Console - What does "Array(0)" mean? google-chrome google-chrome

Javascript - Chrome Console - What does "Array(0)" mean?


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;