How to remove a Key/Property from an object in JavaScript18 Mar 2025 | 4 min read Introduction:JavaScript objects are made up of properties, which are just key-value pairs. In essence, properties consist of a pair of keys and values that can represent any type of entity. Even functions have the ability to function as a value or a key in any object. Anyway, in this section, we'll talk about how to delete keys from Object JavaScript. A key's associated value is automatically deleted when the key is removed. So, eliminating a key merely entails eliminating that attribute. There are now three ways in JavaScript to remove keys from objects. Let's take a quick look at each one. If necessary, properties in JavaScript objects can be erased. There are three simple methods we can use to quickly erase any object property. The first technique makes use of the delete operator, a particular operator in JavaScript, the second method makes use of Object Destructuring, and the third method makes use of the Reflect.deleteProperty() method. 1. Remove a Property from a JavaScript Object Using the Delete Operator:The delete operator is a specific operator in JavaScript. If we want to remove a key from an Object JavaScript, use the delete operator. The delete operator does exactly what its name implies: it removes the supplied property from the object. Although, we must first gain access to the property to delete it. Either the dot property accessor or the square brackets property accessor can be used to access the Object property. Delete with the Dot Method:Syntax: Example: output: { name: "saswat", age: 26, designation: "Software Engineer" } age: 26 designation: "Software Engineer" name: "saswat" Let's remove the age property in a dot-based manner. Output: { name: "saswat", designation: "Software Engineer" } designation: "Software Engineer" name: "saswat" Explanation: We can see from the output above that the delete operator was effective in deleting the object emp's property age (dot way). Delete with the square bracket method:Syntax: Let's use square brackets to delete the designation property from the same object emp. Output: { name: "saswat", age: 26 } name: "saswat" age: 26 Explanation: We can see from the output above that the delete operator was successful in deleting the object emp's property designation (square brackets way). 2. Remove a Property from a JavaScript Object Using Object Destructuring:Object destructuring can also be used to remove a property from an object, but there's a catch. Instead of altering the original object, a new object that doesn't include the deleted property is created. In this manner, the original item is preserved (does not change). Syntax: Example: Output: { brand: "HP", year: 2020 } { brand: "HP", model: "Notebook", year: 2020 } Explanation: In the aforementioned example, we removed a property from an object using object destructuring. When we used object destructuring to remove the property model from the original object laptop, we obtained the new object myLaptop without that property. Once more, the output demonstrates that the original item remained unchanged. 3. Remove a Property from a JavaScript Object Using the Reflect.deleteProperty()Method:The Reflect.deleteProperty() method is provided by one of the built-in JavaScript objects called 'Reflect'. This approach is analogous to the delete operator's function form, which we have discussed. Example: Output: { car1: 'Honda', car3: 'Toyota' } Explanation: In the example above, there was an object called "cars" that had three properties. To remove the car2 property from that object, we used the Reflect.deleteProperty() method. The output demonstrates that deleting the car2 property from the cars object was successful. Finally, we'd like to say that it makes no difference whether you use the delete operator or the Reflect.deleteProperty() method because they both do the work with essentially the same temporal complexity. However, utilising Object Destructing takes more time. Hence, due to its simple syntax and low time complexity, the delete operator is the most popular method of removing keys from javascript objects. ConclusionJavaScript objects are made up of properties, which are just key-value pairs. A key's associated value is automatically deleted when the key is removed. Next TopicJavaScript Endswith() Function |
? PI is a mathematical constant. The lowercase Greek letter π represents the symbol PI. It is an acronym of the periphery. PI can be defined as the circumference (C) of a circle divided by its diameter (d). It means that for any size of the circle,...
2 min read
In this article, we will understand how to remove an option from the select list with the help of JavaScript. At the beginning of this article, we will learn some fundamental aspects of JavaScript, <select> tag, and remove method in JavaScript. After that, we will...
6 min read
The ability to track DOM tree modifications is provided via the MutationObserver interface. It is intended to take the place of the ious Mutation Events functionality, which was included in the DOM3 Events definition. The DOM can often change in complex web projects. Because of this,...
7 min read
The unique feature of async generator functions in javascript is their support to both await and yield. It returns an async iterator rather than a promise or iterator. The async generator functions are distinct from async functions and the generator functions in javascript. The () function...
3 min read
The focus method uses the html field where the user needs to focus on a particular area. It is used on the user-interface tag or input tag. This javascript method uses for multiple input fields in the web page, and the user does not get...
3 min read
The JavaScript textContent property works to set and get the page's text content. It is used to pass and display the text content of some information, tags, and large size of data and its nodes. The TextContent varies from the nodeValue of the script tag...
5 min read
? A radio button is an icon that is used in forms to take input from the user. It allows the users to choose one value from the group of radio buttons. Radio buttons are basically used for the single selection from multiple ones, which is...
8 min read
In this section, we will take an introduction of the queue and also see how to implement a queue in JavaScript. What is Queue? A queue is a data structure where the data is organized in the form of a queue. We can understand a queue similar...
6 min read
When a user tries to load a page but it is unsuccessful, the page remains unloaded, and a JavaScript onunload event is triggered. The possibility exists that the onunload event will also happen if the browsers have been closed while the page is loaded. When a...
3 min read
JavaScript code can be run independently in a browser using the open-source, cross-platform Node.js runtime environment. The "npm" represents "Node Package Manager". The Node.js package manager is used to install various internet packages as well as dependencies into a local environment using a command-line tool. It is...
3 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India