When a user checks one or more of the four categories (Error, Warning, Info, and Debug) on my checkbox, I need to include them in an httpclient call query.
For instance, if all categories are checked, the query should look like this: (category=eq=Error,category=eq=Warning,category=eq=Info,category=eq=Debug)
I attempted to achieve this by creating a string object and concatenating each category if it is checked:
if (obj.category) {
const ctgLength = obj.category.length; //number of categories checked by the user
object["(category=eq"] = obj.category[0];
for (let i = 1; i < ctgLength - 1; i++) {
console.log(obj.category[i]);
object[",category=eq"] = obj.category[i] + ",";
}
object["category=eq"] = obj.category[ctgLength - 1] + ")";
}
However, the resulting query only includes the values from the last iteration of the loop, e.g., (category=eq=Error,category=eq=Info,category=eq=Debug).
My questions are: Firstly, is this method an effective way to generate a query for my situation? Secondly, how can I modify this code to ensure that all checked categories are included in the query?
Thank you.