When retrieving data from a database table, I receive values of "yes" or "no" to indicate whether a specific item is available. Instead of simply concatenating the names with the values, I am looking for a way to create a string that lists only the available products by name.
One approach I'm considering involves using a series of if statements to assign each product name to a variable based on its availability status, and then including all the variables in the final string:
var kt;
if (kitchenTable == yes) kt = "kitchen table";
else kt = "";
var kc;
if (kitchenCabinet == yes) kc = "kitchen cabinet";
else ka = "";
output = kt + ', ' + kc;
Since there are approximately 50 items to be considered, I'm exploring more efficient solutions to this problem. One potential option is to modify how the data is stored in the database table so that instead of "yes," the entry would include the actual item name. However, this might not be the best solution overall.