Question

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.

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top