1//use trim() on your string. It removes first and last whitepsaces
2
3let str = " aa bb ";
4console.log(str.trim()); // "aa bb"
1function rtrim(str, ch)
2{
3 for (i = str.length - 1; i >= 0; i--)
4 {
5 if (ch != str.charAt(i))
6 {
7 str = str.substring(0, i + 1);
8 break;
9 }
10 }
11 return str;
12}