Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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' } }
] Advertisements
