Add Properties to JavaScript Object Example

This JavaScript example shows how to add new properties to an existing object by simply giving it a value. 

Add Properties to JavaScript Object Example

Let's create a user object with few properties and add new fullName property to an existing user object.
var user = {
    firstName : 'Ramesh',
    lastName : 'Fadatare',
    emailId : 'ramesh@gmail.com',
    age : 29
}

user.fullName = user.firstName + " " + user.lastName;
console.log(user.fullName);
Output:
Ramesh Fadatare
Note that in the above example, we have added fullName property to an existing user object:

user.fullName = user.firstName + " " + user.lastName;

Comments