How to remove a character at the end of the string if there is one?

Good evening! I can not understand how to do it.
There is such a line:
string:string:
or such
string:string

It is necessary that the string was always in the format
string:string
ie, without the : at the end

Like the solution on the surface, but the brains could not figure out, please help.
April 19th 20 at 12:23
2 answers
April 19th 20 at 12:25
Solution
str.replace(/:$/, ")
As always, the answers are your best of the best. Thank you very much!!! - melvina.Renner20 commented on April 19th 20 at 12:28
April 19th 20 at 12:27
let str = "string:string:";
let res = str.slice(0, -1);
alert(res);


JsFiddle
Thank you for the response, this decision I know. I get stuck on the fact that symbols not be in the end - melvina.Renner20 commented on April 19th 20 at 12:30

Find more questions by tags JavaScript