I want to check multiple variables if they're containing a certain string. Therefore I'm using the includes method. This is working so far.
But how do I get the name of the variable which is containing the wanted string? In the following example I need to get "categoryopt2" as the output.
This is the JSFiddle.
Code:
var categoryopt1 = '';
var categoryopt2 = "test";
if (categoryopt1.includes('test') || categoryopt2.includes('test')) {
// in this case get "categoryopt2" as a variable:
var matchvariablename = "categoryopt2";
}