Scott Mitchell
Scott Mitchell

Reputation: 8759

Add properties to an object after definition?

I know that in JavaScript you can add new properties to an instance of an existing type (like Date), but is it possible to add new properties to an instance of an anonymous type after it's been defined?

For example, say I have the following script:

var employee = {
    'Name': 'Scott',
    'Age': 32,
    'JavaScriptNewbie': true
};

Later on in my script I want to add a new property to this employee object (say, Salary). Is that possible?

Upvotes: 11

Views: 3077

Answers (1)

Quentin
Quentin

Reputation: 943108

employee.Salary = value;

Upvotes: 16

Related Questions