Array has elements but length is 0

Simon

I use an array which contains separate arrays and push objects in it.

My push looks like:

this.storeFilesService.base64files.filetype1.push({name: file.name, base64: str});

After I push an object into the subarray I log the array to the console. console.log

(this.storeFilesService.base64files.filetype1);

Console output is:

[]
|-> 0: {name: "filename.pdf", base64: "JVBERi"}

But when I log the length of the array to the console the output is 0.

console.log(this.storeFilesService.base64files.filytype1.length);  -> 0

I am trying to check if the subarray contains objects, but my if clause seem to fail, cause of the length.

The oboce code is set in an angular onInit / constructor method. Befor this i execute an async promise in the last component within the onDestroy method. I think all promises should have been resolved when i reach the above code.

Why is this behaviour?

Update: Tried a JSON console log

console.log('Array : ', this.storeFilesService.base64files.filytype1, JSON.stringify(this.storeFilesService.base64files.filytype1));

JSON -> [] Object -> same as above, contains the object.

How is this even possible?

Simon

Seem to be related to the live console by chrome. The value was updated by chrome in the console even after it was already printed.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Array shows 0 as length when it has elements in it

Angular 2 array after subscribe has elements but length is 0

array.length is zero, but the array has elements in it

Array has elements on it but its length is zero

Array length is zero but has accessible elements

array length is 0 even though it has values

Array length is 0 even though it has items

c# array has always the length of 0

Array has two elements; array.length returns 20

Array has records but showing array length 0 in console

Resolving Elements in Array when Array Length is 0 (MongoDB, React, Axios)

Array list is shown, array length is 0 and elements are undefined in react

My array appears to have entries but it has a length of 0

IndexOutOfRangeException in C# – Why has length of array become 0?

c++ empty char array has length > 0

Why do Array literals with commas but no elements not have a length of 0?

Function returning Array[0] when array has elements | Typescript/Javascript

Length mismatch: Expected axis has 0 elements, new values have 3 elements

Variable Length Array with length 0?

Use of Array of length 0?

Array Length returns 0

Javascript array length of 0

The length of this integer array is 0?

ValueError: Length mismatch: Expected axis has 0 elements while creating hierarchical columns in pandas dataframe

Length of elements using jQuery is 0

Checking if a numpy array has the same number of elements across its length and width

For loop with the length of array that has values

The JS Array used for the second time has length equals '0' but contained objects

I have a JSON array with 4 elements in angular 7, but it shows 0 when I asked for it`s length