Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

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.

share|improve this answer
    
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. –  Miller May 16 '13 at 3:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.