1

Please help me to get the property of the embedded object React redux:

{
  "id":1
  "name":"Jonh"
  "pets": {
    "namepets": {
      "String":"King-kong"
      "Valid": true
    },
    "age": {
      "String":"11",
      "Valid": true
    }
  }
}

If i write console.log(this.props.user.pets), I see this object in my console, but I write console.log(this.props.user.pets.namepets).

I have this error:

TypeError: Cannot read property 'namepets' of undefined

How do I get this value?

1
  • 2
    There's no explanation if console.log occurs in same place. If it's really undefined, console.log(this.props.user.pets) cannot output an object. Consider providing a way to replicate the problem. Commented Feb 8, 2019 at 15:05

1 Answer 1

1

If you're getting this object:

{"id":1,"name":"Jonh","pets":{"namepets": {"String":"King-kong","Valid": true}, "age": {"String":"11","Valid": true}}}

After checking this.props.user.pets, then the full property of this would be:

this.props.user.pets.namepets.pets.namepets

(Not very pretty is it)

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

1 Comment

console.log(this.props) and post the result. Post ANY console.log()'s that have been outputted. (Even if there is multiple)

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.