I have a String like this in Javascript:
string = '@usernameWhats on your mind?'
I need to get rid of 'Whats on your mind?'
from the string.
How would I do that?
We can remove part of the string using REPLACE() function. We can use this function if we know the exact character of the string to remove. REMOVE(): This function replaces all occurrences of a substring within a new substring.
JavaScript String trim() The trim() method removes whitespace from both sides of a string. The trim() method does not change the original string.
Overview. The replace() method can be used in a TypeScript string to replace a particular substring or a match (regular expression) in a string. All we need to do is pass the substring or regular expression of the substring we want to replace.
The substring() method returns the part of the string between the start and end indexes, or to the end of the string.
var new_string = string.replace('Whats on your mind?', '');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With