Summer Sale! All accounts are 50% off this week.

GodziLaravel's avatar

array length returns zero but console.log returns values!

Hello ,

I try to foreach() the array formaCompetenceLogs in the script bellow and nothing happens!

At the same time when I console.log(formaCompetenceLogs); I see the content!:

[12/11/2019: Array(2), 13/11/2019: Array(1), 14/11/2019: Array(2), 15/11/2019: Array(4)]
12/11/2019: (2) ["wheel_null", "wheel_6"]
13/11/2019: ["wheel_6"]
14/11/2019: (2) ["wheel_6", "wheel_3"]
15/11/2019: (4) ["wheel_2", "wheel_2", "wheel_1", "wheel_null"]

but when I console.log(formaCompetenceLogs.length); it returns zero 0!

            getCompetenceLogs() {
                axios.get(`api/competence-logs/`+this.loginUserId)
                    .then(response => {
                        this.competenceLogs = response.data;



                        let formaCompetenceLogs = [];
                        let wheelsId = [];
                        this.competenceLogs.forEach(
                            (item)=>{
                                let date = moment(item.created_at).format('DD/MM/YYYY').toString();
                                let wheel = "wheel_"+item.wheel_id;
                                let properties = item.properties;

                                if(wheelsId[wheel] === undefined){
                                    wheelsId[wheel] = [properties];
                                }else{
                                    wheelsId[wheel] =  wheelsId[wheel].concat(properties);
                                };

                                if(formaCompetenceLogs[date] === undefined){
                                    formaCompetenceLogs[date] = [wheel];
                                }else formaCompetenceLogs[date] = formaCompetenceLogs[date].concat(wheel);

                            }
                        );


                        console.log(formaCompetenceLogs.length);
                        console.log(formaCompetenceLogs);


                    });
            },
´´´
0 likes
2 replies
Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

You seem to try to mix array and object syntax. The keys on an array should be 0, 1, 2 and so forth, not date strings

Please or to participate in this conversation.