1

Within the context of React/Meteor I'm running into some surprising difficulty extracting information from a nested Javascript Object.

My data structure looks like this (taken from inspection in chrome dev tools:

Object {
id: "138451",
name: "Attendant",
 key: "Taiwan", 
defaultAnimation: 2, 
position: Object
 {
latitude:0.5,
longitude: -0.14
}

Within my React ComponentWillRecieveProps I see the following behaviour

componentWillReceiveProps(nextProps){
  console.log("its getting props");
  console.log(nextProps.markers[0]) // this works
  console.log(nextProps.markers[0].position) //so does this
  console.log(nextProps.markers[0].position.longitude) //breaks 

I also tried setting var positionObject = nextProps.markers[0].position but interrogating this object also fails. Please highlight my Javascript noobish mistake.

Thanks!

7
  • What is returning value nextProps.markers[0].position? Commented Oct 11, 2016 at 10:49
  • Hi Yasemin, this returns >Object {latitude: 51.5193, longitude: -0.140725} Commented Oct 11, 2016 at 10:58
  • i dont understand why you dont access to nextProps.markers[0].position.longitude Commented Oct 11, 2016 at 10:59
  • 1
    And what do you get with nextProps.markers[0].position.longitude? Is it undefined? Commented Oct 11, 2016 at 11:01
  • 1
    Your code is right accroding to javascript.I think you miss the something in react. Commented Oct 11, 2016 at 11:08

0

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.