var value = "${variable}";
if (value.indexOf(",") !== -1) {
return value.split(",")[0].trim();
} else {
return value;
}
What is the alternative?
${...} in script commands is inserted as an already-quoted string, so drop your own quotes:
var value = ${variable};
if (value.indexOf(",") !== -1){
return value.split(",")[0].trim();
} else {
return value;
}
In Firefox, the sandbox rejects split (along with match/replace/exec/search) with E501 … Firefox does not support regular expressions
A cross-browser version that avoids split is:
var value = ${variable};
var i = value.indexOf(",");
return i !== -1 ? value.substring(0, i).trim() : value;