I would discourage using brackets []
on Object
type variables.
Also, you must define attributes/properties in an Object using the attribute : value
notation, so there is no equal sign used.
You can easily achieve what you want using the Object.defineProperty
(MDN) method:
JavaScript
var myObject = {
'12-25-2012': '<p>Christmas</p>',
'07-18-2013': '<p>My Birthday</p>'
};
function myFunction(attribute,value) {
Object.defineProperty(myObject, attribute, {
value: value,
/* This lets you overwrite the value later */
writable: true,
/* This lets you see the attribute in the Object attributes/properties list and in the length too */
enumerable: true,
});
return myObject;
}
/* Displaying the content of the Object */
console.dir(myFunction("07-23-2013","<p>Mom's Birthday</p>"));
alert(JSON.stringify(myObject,null,4));
So you call the function this way : myFunction(TheDate, TheValue);