1

When I attempt to access the array object (preivous_data) the console outputs this:

[Object { label="line1", data=[13]}]

as expected. However, when I access the array object property (preivous_data.data) the console gives undefined. I am confused - what error am I making for this not to display the array values for the property data in the object?

As a further test, I converted the object with JSON.stringify, then back into a JavaScript object. Again I found the same issues with accessing the property value of the object:

function dataUpdate(passed_onDataReceived_data){

      console.log("passed object")                     // console output:  passed object

      preivous_data = passed_onDataReceived_data
      console.log(preivous_data)                       // console output: [Object { label="line1", data=[13]}]
      console.log(preivous_data.data)                  // console output: undefined

      var JSON_Stringify = JSON.stringify(preivous_data);
      console.log(JSON_Stringify)                     // console output:[{"label":"line1","data":[[0,88],[1,28],[2,52],[3,7],[4,93],[5,78],[6,53],[7,64],[8,43],[9,77],[10,58],[11,74],[12,5]]}]
      var myObject = eval('(' + JSON_Stringify + ')')
      console.log(myObject)                           // console output: [Object { label="line1", data=[13]}]
      console.log(myObject.data)                      // console output: undefined
}

Any help would be appreciated.

1 Answer 1

6

Looks like you have the object previous_data as an array.

[Object { label="line1", data=[13]}]

So you need to do previous_data[0].data to access the data attribute.

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

1 Comment

Thank you for the answer. To solve the answers while waiting for help I decided to grab copy the data attribute to a new var, then manipulate it and then update the passed_onDataReceived_data.

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.