javascript object instantiation to include an array as one of the properties
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.
精彩评论