I am trying to filter data which are present in an array using lodash. I am trying to filter like SQL IN clause.
ex: - select * from Test where id IN (2,4,5,67);
JSON:
storedData = [
{
"id" : 1,
"name" : "ABC"
},
{
"id" : 2,
"name" : "XYZ"
},
{
"id" : 3,
"name" : "BVX"
},
{
"id" : 4,
"name" : "OOO"
}
]
Search criteria:
[2,4,5,67]
Required Output:
output = [
{
"id" : 2,
"name" : "XYZ"
},
{
"id" : 4,
"name" : "OOO"
}
]
Below is my code which i tried to implement
output = _.filter(storedData, (value) => {
return value.id == 2 || value.id == 4 || value.id == 5 || value.id == 67
});
Could you please help me how to filter like IN clause ?