Delete spaces in variable value

The value of the variable I got from excel is “Castillo Roncancio, Monica Pilar.” (the location of the spaces varies for each line) I split the script by comma, and it says “var str= name. split(”, “); var FirstName= str[0];” I want to capture only the “Castillo Roncancio” data, but I get an error because there is a space. In this case, is there a way to delete the trailing spaces before the comma in a different script or variable value?


I solved the problem by using the trim method to eliminate spaces to the right and left of the comma when splitting by comma.

var str = execution.getVariable(“name”);
str= str.trim();
var arr = str.split(“,”);
str = arr[0];