Currently, my task involves searching for data in localStorage, then pushing this data (objects) to an array. However, when attempting to loop through this array of objects, I encounter an issue where the length is 0. I understand that I need to use async/await, but I am struggling to grasp how it functions.
this.afAuth.authState.subscribe(user => {
if (user) {
this.Uid = user.uid;
this.storage.get(this.Uid ).then((val) => {
this.CaloriesChartData = JSON.parse(val);
if (this.CaloriesChartData != null) {
this.CaloriesChartData = Object.keys(this.CaloriesChartData).map(key => ({ type: key, value: this.CaloriesChartData[key] }));
this.CaloriesChartDataLength = this.CaloriesChartData.length;
for (let i = 0; i < this.CaloriesChartDataLength; i++) {
this.CaloriesArray.push(this.CaloriesChartData[i].value);
}
}
console.log(this.CaloriesArray);
console.log(this.CaloriesArray.length);
});`
Upon inspection, I notice that the array is displayed as empty [], but expands when examined. The length is also shown as 0.