admin管理员组文章数量:1332201
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.
本文标签: Javascript Array Object Property UndefinedStack Overflow
版权声明:本文标题:Javascript Array Object Property Undefined - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742261103a2442528.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论