- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How to remove an object using filter() in JavaScript?
Let’s say, we have the following objects in JavaScript −
ObjectValue =[ { "id": "101", "details": { Name:"John",subjectName:"JavaScript" }}, { "id": "102", "details": { Name:"David",subjectName:"MongoDB" }}, { "id": "103" } ]
To remove an object using filter(), the code is as follows −
Example
ObjectValue =[ { "id": "101", "details": { Name:"John",subjectName:"JavaScript" }}, { "id": "102", "details": { Name:"David",subjectName:"MongoDB" }}, { "id": "103" } ] output=ObjectValue.filter(obj=>obj.details) console.log(output)
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo46.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo46.js [ { id: '101', details: { Name: 'John', subjectName: 'JavaScript' } }, { id: '102', details: { Name: 'David', subjectName: 'MongoDB' } } ]
- Related Articles
- Remove elements from array using JavaScript filter - JavaScript
- Filter an object based on an array JavaScript
- Filter nested object by keys using JavaScript
- How to remove all blank objects from an Object in JavaScript?
- How to filter values from an array using the comparator function in JavaScript?
- Excel Filter: How to Add, Use and Remove filter in Excel
- Remove number properties from an object JavaScript
- How to find duplicates in an array using set() and filter() methods in JavaScript?
- How to clone an object using spread operator in JavaScript?
- Remove/ filter duplicate records from array - JavaScript?
- How to modify key values in an object with JavaScript and remove the underscore?
- Filter the properties of an object based on an array and get the filtered object JavaScript
- How to convert a bean to JSON object using Exclude Filter in Java?
- How to access an object value using variable key in JavaScript?
- Iterate over an object and remove false property in JavaScript

Advertisements