how to add-remove property in Javascript Object?

Suppose I have a javascript Object

var MyObject= {
    "Name": "Value1",
    "Email": ""   

And now I want to add a new property or remove a property from the above object, how can I achieve it in javascript?

Asked by:- pika
: 1638 At:- 6/20/2017 3:17:39 PM
javascript add-remove javascript-objects

1 Answers
profileImage Answered by:- Vipin

you can delete object using delete


delete MyObject.Name;
// or,
delete MyObject['Name'];
// or,
var prop = "Name";
delete MyObject[prop];

Another way to delete an object is to undefined it

obj.field = undefined;

//use this approach when you care about performance

Adding a property to object

Adding a proerty is easy, if you know the basics of Javascript Objects

MyObject.NewProperty = "NewValue";

//you can get the value using 


At:- 6/21/2017 8:21:04 AM

Login/Register to answer
Register directly by posting answer/details

Full Name *

Email *

By posting your answer you agree on privacy policy & terms of use