How can I filter JSON data with multiple objects?


To filter JSON data with multiple objects, you can use the concept of filter along with ==.

Example

const jsonObject=
[
   {
      studentId:101,
      studentName:"David"
   },
   {
      studentId:102,
      studentName:"Mike"
   },
   {
      studentId:103,
      studentName:"David"
   },
   {
      studentId:104,
      studentName:"Bob"
   }
]
var result=jsonObject.filter(obj=> obj.studentName == "David");
console.log(result);

To run the above program, you need to use the following command −

node fileName.js.

Output

Here, my file name is demo194.js. This will produce the following output −

PS C:\Users\Amit\javascript-code> node demo194.js
[
   { studentId: 101, studentName: 'David' },
   { studentId: 103, studentName: 'David' }
]

Updated on: 14-Sep-2020

15K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements