by Sai gowtham

Two ways to remove a property or key from a Javascript Object

In this tutorial, we are going to learn about two different ways to remove a property from the JavaScript object.

First way

delete keyword in JavaScript helps us to remove a property from the objects.

let bike = {
    color: "red",
    model: "150ac"
}


delete bike.color

// bike.color property is removed from the object


console.log(bike);

//output {model: "150ac"}

This is also a valid syntax.

delete bike['color']

delete bike['model']

Second way

Reflect.deleteProperty() method is also used to remove a property from the javascript objects.

let bike = {
    color: "green",
    model: "150edc"
}


Reflect.deleteProperty(bike,'color')

console.log(bike)

//output {model: "150edc"}

Reflect.deleteProperty() method accepts two arguments which are the target and propertyKey.

target: On which object you need to remove the property.

propertyKey: name of the property you want to remove.

Css Tutorials & Demos

How rotate an image continuously in CSS

In this demo, we are going to learn about how to rotate an image continuously using the css animations.

How to create a Instagram login Page

In this demo, i will show you how to create a instagram login page using html and css.

How to create a pulse animation in CSS

In this demo, i will show you how to create a pulse animation using css.

Creating a snowfall animation using css and JavaScript

In this demo, i will show you how to create a snow fall animation using css and JavaScript.

Top Udemy Courses

JavaScript - The Complete Guide 2021 (Beginner + Advanced)
JavaScript - The Complete Guide 2021 (Beginner + Advanced)
64,026 students enrolled
52 hours of video content
View Course
React - The Complete Guide (incl Hooks, React Router, Redux)
React - The Complete Guide (incl Hooks, React Router, Redux)
284,472 students enrolled
40 hours of video content
View Course
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
Vue - The Complete Guide (w/ Router, Vuex, Composition API)
152,857 students enrolled
48.5 hours of video content
View Course