开发者

javascript object instantiation to include an array as one of the properties

开发者 https://www.devze.com 2023-03-19 05:22 出处:网络
I am trying to create an object which includes an array stPoints as one of its properties. I am getting an error message saying that stPoints is undefine开发者_JS百科d. What is the proper way to decla

I am trying to create an object which includes an array stPoints as one of its properties. I am getting an error message saying that stPoints is undefine开发者_JS百科d. What is the proper way to declare an array property within an object?

this is my code:

var temp={stName:"#states.stateid#",stPoints:[]};


This is correct. You must be referencing it incorrectly.

temp.stPoints


var temp={ 'stName':"#states.stateid#", 'stPoints':[] };

However, if the property name is a valid javascript identifier, as in this case, you should not have problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消