let users = [
{
"id": 1,
"name": "Ricardo",
"serail_no": 463494,
"occupation": "IT Specialist"
},
{
"id": 2,
"name": "Saptak",
"serail_no": 749694,
"occupation": "Teacher"
},
{
"id": 3,
"name": "Antonio",
"serail_no": 406406,
"occupation": "IT Specialist"
},
{
"id": 4,
"name": "Dimitri",
"serail_no": 2503853,
"occupation": "Doctor"
}
]
From the above Array List, I want to display only the objects which has same occupation in it.
So from the above list, if I take occupation = IT Specialist
, then I ony want to display
[{
"id": 1,
"name": "Ricardo",
"serail_no": 463494,
"occupation": "IT Specialist"
},{
"id": 3,
"name": "Antonio",
"serail_no": 406406,
"occupation": "IT Specialist"
}]
I tried it using filter method, but wasn’t able to achieve it.
Will be very much grateful, if anyone helps me out in it with explanation.
2
Answers
this should work 🙂
Here is how you would use filter: