For example, this string:
"The dog goes bark. "
Should be converted to a new version with the spaces removed:
"The dog goes bark."
Regular expression (supported by all browsers):
This will remove any trailing spaces in your string.
Use it like this:
let string = " My example string. " string = string.replace(/\s+$/, ""); // " My example string."
trimEnd() method (supported by all browsers besides IE):
trimRight() will work for you. It removes trailing spaces from your string.