Я пытаюсь сделать фильтр, используя contains
.но не работает.любой разобрался в проблеме здесь.
const nestedFilter = (targetArray, filters) => {
var filterKeys = Object.keys(filters);
return targetArray.filter(function(eachObj) {
return filterKeys.some(function(eachKey) {
return eachObj[eachKey].includes(filters[eachKey]);
});
});
};
let filter1 = {Id: "24", Name: "Api Gateway"};
let products = [
{
"Id": 100024,
"Name": "Api Gateway UpdateXX",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "B, Mohamedarif (Cognizant)",
"CreatedDate": "2019-21-17T06:35:20.107Z"
},
{
"Id": 100026,
"Name": "Chennai became cold very soon!!",
"Description": "stridfgdfgng",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100031,
"Name": "Soma Banerjee",
"Description": "Updated for Testing2",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100032,
"Name": "Soma Banerjee",
"Description": "Soma Banerjee",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100033,
"Name": "Update Same Data Contact",
"Description": "Update Same Data Contact",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100034,
"Name": "New",
"Description": "New Des",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100039,
"Name": "100001 New111",
"Description": "100001 New",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100041,
"Name": "3 way entry",
"Description": "3 way entry",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100042,
"Name": "3 way entry1",
"Description": "3 way entry",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100043,
"Name": "ghgjhlk",
"Description": "sdfsfs",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100044,
"Name": "ghgjhlk",
"Description": "sdfsfs",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100045,
"Name": "Azure New",
"Description": "Azure New",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100047,
"Name": "2 way",
"Description": "2 way",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100049,
"Name": "C2-new",
"Description": "C2-new",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100050,
"Name": "C0001-new",
"Description": "C00012-new",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100051,
"Name": "Common Add",
"Description": "Common Add",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100053,
"Name": "Mama",
"Description": "Mama",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100054,
"Name": "New title",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100055,
"Name": "CTS",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100056,
"Name": "New course added",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100057,
"Name": "Chennai 2020",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100058,
"Name": "updated Course",
"Description": "Updated Course",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100059,
"Name": "New Coursegfdgdfg",
"Description": "New Course",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100061,
"Name": "New Cosmos",
"Description": "Cosmos",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100062,
"Name": "New Cosmos2222",
"Description": "Cosmos222",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100063,
"Name": "New Cosmosooooo",
"Description": "Cosmoooooo",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100064,
"Name": "New Cosmo123",
"Description": "Cosmo123",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100066,
"Name": "New dfsfsfsd",
"Description": "Cosmosdfsfsfds123",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100068,
"Name": "Using good",
"Description": "strisdfsfsdfng",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100077,
"Name": "Nadu Nadu",
"Description": "NaduNadu",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100078,
"Name": "Course 0013 for Albanian literature",
"Description": "Course 0012 for Albanian literature",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100079,
"Name": "Course 0002 for Albanian literature",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100080,
"Name": "Course 0003 for Albanian literature",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100081,
"Name": "a-z",
"Description": "a-z",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100082,
"Name": "Course 0004 dipa",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100083,
"Name": "Update",
"Description": "Up",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100084,
"Name": "fsdfsfsfs",
"Description": "ssdfsdfsftrisdfsdfng",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100086,
"Name": "fsdfsfsfs",
"Description": "ssdfsdfsftrisdfsdfng",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100087,
"Name": "dsdsdfsfsdfs",
"Description": "strdfsdfsdfsfsding",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100088,
"Name": "dsdsdfsfsdfs",
"Description": "strdfsdfsdfsfsding",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100089,
"Name": "dsdsdfsfsdfs",
"Description": "strdfsdfsdfsfsding",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100090,
"Name": "dsdsdfsfsdfs",
"Description": "strdfsdfsdfsfsding",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100091,
"Name": "100001",
"Description": "st100001ring",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100092,
"Name": "100001",
"Description": "st100001ring",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100093,
"Name": "fdgdfdgdgdfgdf",
"Description": "st1000dsfgddfgdg01ring",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100095,
"Name": "testservice",
"Description": "LogicAppVS",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
},
{
"Id": 100096,
"Name": "TestingLogicApp",
"Description": "VisualSTudio",
"CreatedBy": "Script",
"CreatedDate": "2019-04-17T06:35:20.107Z"
}
]
console.log(nestedFilter(products, filter1));//getting error.
смотря результат:
{
"Id": 100024,
"Name": "Api Gateway UpdateXX",
"Description": "Course 0002 for Albanian literature",
"CreatedBy": "B, Mohamedarif (Cognizant)",
"CreatedDate": "2019-21-17T06:35:20.107Z"
}
заранее спасибо.
Live Demo