Sometimes, we want to remove part of a string before a ":" in JavaScript.
In this article, we’ll look at how to remove part of a string before a ":" in JavaScript.
How to remove part of a string before a ":" in JavaScript?
To remove part of a string before a ":" in JavaScript, we call the string split
method and the array pop
method.
For instance, we write
const str = "abc: Lorem ipsum sit amet";
str = str.split(":").pop();
to call split
with ':'
to split the string by the colons.
And then we call pop
to remove the part after the colon from the returned array and return it.
Conclusion
To remove part of a string before a ":" in JavaScript, we call the string split
method and the array pop
method.