Removing space at the end of a word

Asked

Viewed 169 times

1

I created an application in React Enable and it searches online via POST. It works well, the point is that some devices include a space at the end of words, ex:

The user types natação, but the phone sends natação_ with a space at the end (put underline just to facilitate the vision).

How do I remove the end space before making the query?

1 answer

4


Call the method trim of the string before using it.

Try:

let foo = 'natação ';
console.log(foo.trim());

The method trim removes all spaces at the end of the string, if there is more than one.

  • thanks, just one thing: if you have spaces between words it excludes too? because only need exclusion at the end

  • 2

    @Italorodrigo Não. trim is only at the beginning and end of the String all. View documentation

Browser other questions tagged

You are not signed in. Login or sign up in order to post.