regex to remove space at the end of string code example Example: regex to remove spaces //.. return str.replace(/\s/g, ''); //..