javascript remove period from end of string

Solutions on MaxInterview for javascript remove period from end of string by the best coders in the world

showing results for - "javascript remove period from end of string"
Charlotte
20 Nov 2018
1// Single dot:
2if (str[str.length-1] === ".")
3    str = str.slice(0,-1);
4// Multiple dots:
5while (str[str.length-1] === ".")
6    str = str.slice(0,-1);
7// Single dot, regex:
8str = str.replace(/\.$/, "");
9// Multiple dots, regex:
10str = str.replace(/\.+$/, "");