0

I am trying to access to an object in side an array of array. Here is how my console.log showing:

0:
Memberships: Array(1)
0:
teamId: "5413e75f-ff12-4b7a-a3fe-f892cd006366"
__proto__: Object
length: 1
__proto__: Array(0)
Ratings: []
Skills: []
fullname: "Nhan Nguyen"
institution: ""
linkedin: ""
location: ""
major: ""

So now I want to get access to teamId which is inside an array of array, here is my following code:

{invitees?.map((user, index) => (
  <Grid item className="invitees-card" key={index}>
    {user.Memberships[0].teamId !== teamId && (
    <InviteCard tab={tab} user={user} />
    )}
  </Grid>
))}

it gave me .teamId is undefined which is I think my syntax is wrong but is there any way I can access to teamId without doing another mapping?

2

1 Answer 1

1

Some of the objects don't have a membership property so you should use a null safe operator: user?.Membership[0]?.teamId

Or do user.Membership && user.Membership[0].teamId to guard against undefined

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

5 Comments

How can I just show user that have the teamId is null ?
@nathan you want to display a list of such users?
Yes I want to display list of user that have different teamId or have not have teamId yet
@nathan something like invitees.filter(user => !user.Membership)
If I wrote like you it giving me no data back but If I wrote like this .filter((userTeamId) => !userTeamId.Memberships?.teamId) It send all the user include user already in the team

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.