const usersLanguageData = {
transactionId: 6847655349501841000,
count: 5,
providerList: [
{
code:['US'],
weekendOfficeHours: false
},
{
code:['US','IND'],
weekendOfficeHours: true
},
{
code:['US','IND','AUS'],
weekendOfficeHours: false
},
{
code:[],
weekendOfficeHours: false
},
{
weekendOfficeHours: true
}
]
};
let filterKeyName1 = ["code"];
let filterValue1 = ['IND','US'];
//let filterValue2 = ['US'];
let filteredProviderData = usersLanguageData.providerList.filter(function(e) {
return filterKeyName1.every(function(a) {
console.log(e[a])
return filterValue1.includes(e[a]);
});
});
console.log(filteredProviderData);
The above snippet showcases the transformation of usersLanguageData into an object. The goal is to apply filters using a specific key, such as 'code' and values like ['IND','US']. This filtering logic retrieves the 2nd and 3rd objects from the usersLanguageData array. Similarly, there's another filter value (filterValue2), currently commented out, which would fetch the 1st, 2nd, and 3rd objects based on the specified criteria.