Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Cannot access to json properties?

I'm receiving a JSON array, and I would like to print every props separately.

If I use:

const rides = this.state.ride;
const rideList = rides.map((ride) =>
    console.log(ride)
)

I'm getting this result in browser:

[1]

but if I change code to this:

const rides = this.state.ride;
const rideList = rides.map((ride) =>
    console.log(ride.id)
)                  /\   THIS DOT

I'm getting nothing.

Ride is defined as:

constructor(props) {
    super(props);
    this.state = {
        ride: [],
        isLoading: false
    }
    this.loadUserRide = this.loadUserRide.bind(this);
}

UPDATE

Now if I like that:

const rides = this.state.ride;       
const rideList = rides.map((ride) => 
console.log(JSON.stringify(ride, null, 2))
)

i'm receiving :

Ride.js:79 {
  "id": 2,
  "id_trainee": "id_teacher_test",
  "id_teacher": "xxx",
  "startDateTime": "id_teacher_test"
}
Ride.js:79 {
  "id": 3,
  "id_trainee": "xxx",
  "id_teacher": "id_trainee_test",
  "startDateTime": "id_trainee_test"
}

If i add ".id" to ride, i'm getting what i wanted. Now i'm curious why it's working in other component: /src/user/profile/Profile.js repo: https://github.com/krukarkonrad/problem

Comments