JavaScript remove leading and trailing spaces

javascript, replace

Solution

try doing

trimmedstr = str.replace(/\s+$/, '');

or maybe

.replace(/ +$/, "");

Problem

Here is a test: ``` console.log(" Golden Katana of the Unflinching Dawn ".replace(/\s+/g,"")) ``` I want to remove the extra spaces at the end of the string but it removes every space in the string, so how could I remove just the extra spaces at the end and just keep `Golden Katana of the Unflinching Dawn`?

Original source

Related problems