In my code, I utilize an array that consists of multiple subarrays and then push objects into it.
The pushing process looks like this:
this.storeFilesService.base64files.filetype1.push({name: file.name, base64: str});
Once I push an object into a subarray, I log the entire array to the console using console.log
.
(this.storeFilesService.base64files.filetype1);
The console output appears as follows:
[]
|-> 0: {name: "filename.pdf", base64: "JVBERi"}
However, despite having objects in the subarray, when I check the length of the array by logging it to the console, the output shows 0.
console.log(this.storeFilesService.base64files.filytype1.length); -> 0
I am attempting to verify if there are indeed objects in the subarray, but my conditional statement based on the length seems to fail.
The mentioned code is being executed within an Angular onInit
or constructor method. Prior to this, I handle an async promise in the previous component's onDestroy
method. I expect all promises to be resolved before reaching the above code.
Why does this behavior occur?
Update: I attempted a JSON console log:
console.log('Array : ', this.storeFilesService.base64files.filytype1, JSON.stringify(this.storeFilesService.base64files.filytype1));
JSON -> [] Object -> same as above, containing the object.
How can this situation even arise?