0

I am receiving an json object with user details from my api request in node, the library uses its own each function to iterate through the object and give the details. I am trying to access specific properties in the object using (.) notation. When I try user.profile I get only the profile which is great, however user.profile.UserProfile, gives me undefined. How can I access UserProfile? This is the code that iterates the object.

const orgUsersCollection = client.listUsers();
console.log(orgUsersCollection);
orgUsersCollection.each(user => {
    console.log(user);
  })
  .then(() => console.log('All users have been listed'));

User {
  id: '',
  status: '',
  created: '',
  activated: null,
  profile:
   UserProfile {
     firstName: '',
     lastName: '',
     login: '',
     email: '' },
  
All users have been listed

1
  • 1
    user.profile is the property, UserProfile is the name of the object's class. Commented Apr 11, 2018 at 15:54

1 Answer 1

1

The log for the object appears bit confusing. There's no property 'UserProfile' in 'user.profile'. Rather you want to write user.profile.firstName

let user = {
  id: '',
  status: '',
  created: '',
  activated: null,
  profile: {
     firstName: 'It Works!',
     lastName: '',
     login: '',
     email: ''
  }
};
console.log(user.profile.firstName)

Sign up to request clarification or add additional context in comments.

1 Comment

how did you know that that was just a class?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.