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.
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 edited May 14, 2013 at 1:32 Simon MᶜKenzie 8,70313 gold badges53 silver badges81 bronze badges asked May 14, 2013 at 1:23 ValVal 1,3505 gold badges23 silver badges40 bronze badges1 Answer
Reset to default 6Looks 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.