D
D
Dima Pautov2020-04-16 20:31:54
JavaScript
Dima Pautov, 2020-04-16 20:31:54

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

There is this line: string:string:.
Or like this: string:string.

The string must always be in the format string:string, i.e. without :at the end.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2020-04-16
@bootd

str.replace(/:$/, '')

P
Peter, 2020-04-16
@Morpheus_God

let str = "string:string:";
let res = str.slice(0, -1);
alert(res);

JsFiddle

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question