Javascript provides two ways to define a property of an object:
- object.propertyName = value;
In this situation, the propertyName is un-editable, and un-computable. you cannot do the following:
object.('property'+'Name')
as you can see
object = {propertyName:value};
object = {'propertyName':value};
they are equal
- you can use a variable as the property name with "[]";
you can do :
var a = "propertyName";
object[a] = value;
and this time you have to use a string
object[propertyName] = value;//error
object["propertyName"] = value;//correct
object = {'propertyName':value};//correct
object = {propertyName:value};//correct