How can we remove a property from a JavaScript object?

Objects are one of the essential building blocks of JavaScript Language. You simply can’t have an application that does not make use of Javascript Objects.

We will checkout how to remove a property from a JavaScript object that you already have defined.

Consider you have defined an Object employee as: 

var employee = {

    “name”: “John Doe”,

    “age”: 25,

    “salary”: 35000,

    “department”: “sales”

};

You want to remove property named “department” from employee object. You can do this with delete statement as:

delete employee.department;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.