Questions about the properties of JS objects

wrote such a method:

                        //
                        for(let i=0;i<this.logData.length;iPP){
                            let address=this.logData[i].id;
                            this.$http(api_member_ship_department,address)
                            .then(res => {
                                //
                                this.logData[i].apr=res;
                            })
                            .catch(code => {
                            this.$message({ type: "error", message: code.message || code });
                            });
                        };

roughly means to request everyone"s department information from the background and add it as an apr attribute to the existing object logData,. The added logData output looks like this:

then I loop out the attribute value of each apr:

for(let i=0;i<this.logData.length;iPP){console.log(this.logData[i].apr)} 

the result is all undefined, which makes me puzzled. I ask God for advice

Mar.07,2022

your process of taking values is asynchronous. I think the possible problem is that when you loop out the attribute value of each apr , this.logdata [I] .apr actually doesn't get the callback data

.
Menu