How to use Destructuring In Javascript
In this approach using destructuring, we extract the key from the JSON object into a variable courses while collecting the rest of the object into res. Printing res shows the JSON object jArr without the “courses” key.
Syntax:
const { propertyToRemove, ...rest } = objectName;
Example: The below example uses the Destructuring to remove an element from json object in JavaScript.
let jArr = {
"company": "w3wiki",
"courses": ["DSA", "Web Tech",
"Placement_Preparation", "DDA"]
};
let { courses, ...res } = jArr;
console.log(res);
Output
{ company: 'w3wiki' }
How to Remove Element from JSON Object in JavaScript ?
In JavaScript, removing elements from a JSON object is important for modifying data structures dynamically. This object manipulation can help us to create dynamic web pages.
The approaches to accomplish this task are listed and discussed below:
Table of Content
- Using delete Keyword
- Using filter Method
- Using Destructuring