Home > Mobile >  Undefined error when access the proprty of an object array
Undefined error when access the proprty of an object array

Time:06-23

Please help me. This is my console.log(response) output .

{   response: 
{     loginStatus: true,
     user: {       
       _id: new ObjectId("62b009706c02b4c04fa111ac"),
       userName: 'Amal', 
      userEmail: '[email protected]', 
      userPassword: '123456'    
 }
}
}

console.log(response.loginStatus) is undefined . How can i access 'loginStatus' property.

CodePudding user response:

Assuming from the object you pasted, you are trying to reach it correctly, and the problem might be the place where you try to reach it. If it comes from a network request, the request might still be in pending state, when you are trying to log.

Can you put some more context? Where are you trying to log it?

CodePudding user response:

Have you tried accessing the field with response.response.loginStatus? If that's your output for the response object the reponse field is nested within.

  • Related