I have an array model, as below:
records:[{
"empid":1,
"fname": "X",
"lname": "Y"
},
{
"empid":2,
"fname": "A",
"lname": "Y"
},
{
"empid":3,
"fname": "B",
"lname": "Y"
},
{
"empid":4,
"fname": "C",
"lname": "Y"
},
{
"empid":5,
"fname": "C",
"lname": "Y"
}
]
Now I have an array of empid's [1,4,5]
.
So now, I need to filter the first array, which contains all the keys in my second.
Output:
records:[{
"empid":1,
"fname": "X",
"lname": "Y"
},
{
"empid":4,
"fname": "C",
"lname": "Y"
},
{
"empid":5,
"fname": "C",
"lname": "Y"
}
]
I can do this using a forEach
loop in angular
, but as I have more than 100 records in my model object, I need a way to handle this in a much cleaner way.
I'm thinking of creating a custom filter, but what is your take on it? (If yes, please provide sample code to achieve this).
includes
)'ll – Zashin