You can change your condition to be:
(v.country === "CHINA" || v.country === "ITALY") && v.Service === "CAFE"
The .filter() method will keep all objects which the callback function returns true for. The above condition will return true when the country is either "CHINA" or (||) "ITALY" and (&&) the Service is equal to "CAFE".
See example below:
const myData = [
{country : "USA" , Service : "PHONE" },
{country : "FRANCE" , Service : "DATA"},
{country : "FRANCE" ,Service : "CAFE"},
{country : "FRANCE" ,Service : "CAFE"},
{country : "CHINA" ,Service : "CAFE"},
{country : "ITALY" ,Service : "CAFE"}
];
let filt = myData.filter((v) => {
return (v.country === "CHINA" || v.country === "ITALY") && v.Service === "CAFE";
});
console.log(filt);
Note that the parentheses around (v.country === "CHINA" || v.country === "ITALY") are required. As && has higher operator precedence than ||, the expression would instead evaluate like so:
v.country === "CHINA" || (v.country === "ITALY" && v.Service === "CAFE")
which will give you incorrect values (as it will return true for when the country is "CHINA", ignoring the value of Service)
You can also make this more dynamic if need be by placing the countries and service you want to keep into a Set, and then checking if the Set .has() the value of v.country and v.Service in it:
const myData = [
{country : "USA" , Service : "PHONE" },
{country : "FRANCE" , Service : "DATA"},
{country : "FRANCE" ,Service : "CAFE"},
{country : "FRANCE" ,Service : "CAFE"},
{country : "CHINA" ,Service : "CAFE"},
{country : "ITALY" ,Service : "CAFE"}
];
const keepCountries = new Set(["CHINA", "ITALY"]);
const keepServices = new Set(["CAFE"]);
let filt = myData.filter((v) => {
return keepCountries.has(v.country) && keepServices.has(v.Service);
});
console.log(filt);
Note: The usage of the Set here is to speed things up if your keepCountries array and keepServices array are large. For this demonstration case, they are small, so the set can be a standard array, which will require you to use .includes() instead of .has() when checking if a value is contained within the array.