Chrome developer tool Array length [duplicate]


This question already has an answer here:

<ul><li> <a href="/questions/4057440/is-chromes-javascript-console-lazy-about-evaluating-arrays" dir="ltr" rel="nofollow">Is Chrome's JavaScript console lazy about evaluating arrays?</a> <span class="question-originals-answer-count"> 6 answers </span> </li> </ul>

<a href="https://i.stack.imgur.com/ujc8I.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/ujc8I.png" data-original="https://i.stack.imgur.com/ujc8I.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Why chrome developer tool showing 0 array length (first line Array[0]) even if there are total 9 objects in it?

At first line of image should be like Array[9] why it is showing Array[0]

<a href="https://i.stack.imgur.com/BGTrA.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/BGTrA.png" data-original="https://i.stack.imgur.com/BGTrA.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

In second image array has 13 objects so it is showing Array[13] not Array[0]


It seems like you are logging the output of the array before you are adding objects to your array. Something like

var arr = []; console.log(arr); arr.push({}); //pushing blank obj

Here, executing this code will result in Array[0] but it does hold your object and will return a length of 1 if you try arr.length.

This might also happen if you are having some sort of Async function which pushes item to your array, which will result in the same thing. For example,

var a = []; setTimeout(function(){ a.push({}); a.push({}); }, 1000); console.log(a);

I think, this behavior is intentional, where Chrome wants to show that initially, your Array was empty, later on, items were pushed on runtime.


  • How to apply custom Fliter formatter in a Slick grid custom cell formatter
  • How do I get the right “this” in an Array.map?
  • Read PHP Session data in node.js
  • Create new node module object from kotlin
  • Runtime error in UVA Online Judge [closed]
  • JSON - slashes not escaping
  • SQL: Getting the physical size of a subset of a table
  • Inversing an interpolation of rotation
  • pip in virtualenv gets ConnectTimeoutError
  • How does this usort cmp function actually work?
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • Marklogic : Query response time is very high
  • Date Conversion from yyyy-mm-dd to dd-mm-yyyy
  • Debug.DrawLine not showing in the GameView
  • Jackson Parser: ignore deserializing for type mismatch
  • Python urlparse: small issue
  • FileReader+canvas image loading problem
  • Initializer list vs. initialization method
  • CSS Linear-gradient formatting issue accross different browsers
  • Using $this when not in object context
  • C# - Is there a limit to the size of an httpWebRequest stream?
  • How do I fake an specific browser client when using Java's Net library?
  • How reduce the height of an mschart by breaking up the y-axis
  • Date difference with leap year
  • Perl system calls when running as another user using sudo
  • Can a Chrome extension content script make an jQuery AJAX request for an html file that is itself a
  • Upload files with Ajax and Jquery
  • Rearranging Cells in UITableView Bug & Saving Changes
  • retrieve vertices with no linked edge in arangodb
  • File upload with ng-file-upload throwing error
  • AngularJs get employee from factory
  • Proper way to use connect-multiparty with express.js?
  • Benchmarking RAM performance - UWP and C#
  • Angular 2 constructor injection vs direct access
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Change div Background jquery
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • apache spark aggregate function using min value
  • python draw pie shapes with colour filled
  • Python/Django TangoWithDjango Models and Databases