I am trying to filter an object from an array of objects. Below is the array of the object.
const groupsList = [
{
"groupId": 1234,
"adminId": 52,
"name": "HHLC Health co",
"directorName": "Mr Daric",
"fax": "5556565655",
"email": "test@test.com",
"status": 1,
"address1": "Akshya Nagar 1st Block 1st Cross",
"districtName": "Berkshire",
"addedDate": "2020-02-01T04:44:54.000Z",
"lastModified": "2020-02-25T10:30:47.000Z"
},
{
"groupId": 12335,
"adminId": 52,
"name": "Appolo Health Group",
"directorName": "Mrs Fatima",
"fax": "5556565655",
"email": "test@test.com",
"status": 1,
"address1": "Akshya Nagar 1st Block 1st Cross",
"districtName": "Berkshire",
"addedDate": "2020-01-13T04:44:54.000Z",
"lastModified": "2020-03-14T10:30:47.000Z"
},
{
"groupId": 546,
"adminId": 52,
"name": "Highlights Health LLC",
"directorName": "Mr Jordan",
"fax": "5556565655",
"email": "test@test.com",
"status": 1,
"address1": "Akshya Nagar 1st Block 1st Cross",
"districtName": "Berkshire",
"addedDate": "2020-02-13T04:44:54.000Z",
"lastModified": "2020-02-14T10:30:47.000Z"
}
]
below is the Object which i want to filter from above array.
const objectReady = {
"groupId": "1234",
"name": "Health",
"addedDate": "01-02-2020",
"lastModified": "25-02-2020"
}
What I have tried:
Here what i have tried with the lodash plugin.
_.filter(groupsList, obj => moment(obj.lastModified).format('DD-MM-YYYY') === objectReady.lastModified || obj.name.toLowerCase().includes(objectReady.name.toLowerCase()) ||
Number(obj.groupId) === Number(objectReady.groupId));
above code works fine just for a single condition,
but for multiple values it is not filtering data.
Expected Result should be :
[{
"groupId": 1234,
"adminId": 52,
"name": "HHLC Health co",
"directorName": "Mr Daric",
"fax": "5556565655",
"email": "test@test.com",
"status": 1,
"address1": "Akshya Nagar 1st Block 1st Cross",
"districtName": "Berkshire",
"addedDate": "2020-02-01T04:44:54.000Z",
"lastModified": "2020-02-25T10:30:47.000Z"
}]