- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove json element - JavaScript?
Let's say the following is our JSON string −
var details = [ { customerName: "Chris", customerAge: 32 }, { customerName: "David", customerAge: 26 }, { customerName: "Bob", customerAge: 29 }, { customerName: "Carol", customerAge: 25 } ]
To remove JSON element, use the delete keyword in JavaScript.
Example
Following is the complete code to remove JSON element −
var details = [ { customerName: "Chris", customerAge: 32 }, { customerName: "David", customerAge: 26 }, { customerName: "Bob", customerAge: 29 }, { customerName: "Carol", customerAge: 25 } ] delete details[0].customerAge; console.log(details);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo211.js −
PS C:\Users\Amit\JavaScript-code> node demo211.js [ { customerName: 'Chris' }, { customerName: 'David', customerAge: 26 }, { customerName: 'Bob', customerAge: 29 }, { customerName: 'Carol', customerAge: 25 } ]
Advertisements