Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove portion of string in Javascript

Tags:

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?

like image 631
Talon Avatar asked Dec 16 '11 02:12

Talon


People also ask

How do I remove part of a string?

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.

How do I crop a string in JavaScript?

JavaScript String trim() The trim() method removes whitespace from both sides of a string. The trim() method does not change the original string.

How do I remove a substring from a string in TypeScript?

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.

What does substring () do in JavaScript?

The substring() method returns the part of the string between the start and end indexes, or to the end of the string.


1 Answers

var new_string = string.replace('Whats on your mind?', ''); 
like image 197
jondavidjohn Avatar answered Sep 20 '22 18:09

jondavidjohn