Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove first 3 letters in JQuery?

How can I remove the first three letters of a string in JQuery?

For example: Turn cat1234 to 1234

like image 720
Jacob Avatar asked Nov 25 '11 10:11

Jacob


People also ask

How do I remove the first character in jQuery?

You can also remove the first character from a string using substring method. let input = "codehandbook" function removeCharacter(str){ return str. substring(1) } let output = removeCharacter(input); console. log(`Output is ${output}`);

How do I remove the first word from a string in jQuery?

To remove the first word from a string, call the indexOf() method to get the index of the first space in the string. Then use the substring() method to get a portion of the string, with the first word removed.

How do I remove the first letter from a string?

To delete the first character from a string, you can use either the REPLACE function or a combination of RIGHT and LEN functions. Here, we simply take 1 character from the first position and replace it with an empty string ("").

How do I get the first character of a string in jQuery?

var header = $('. time'+col). text(); alert(header);


2 Answers

No jQuery needed.

"cat1234".slice(3); 

or

"cat1234".substring(3); 

or

"cat1234".substr(3); 

var str="cat1234";  console.log("using slice =",str.slice(3));  console.log("using substring =",str.substring(3));  console.log("using substr =",str.substr(3));
like image 112
jAndy Avatar answered Oct 16 '22 04:10

jAndy


var val = 'cat1234'; var newVal = val.substring(3, val.length); 
like image 41
Jwalin Shah Avatar answered Oct 16 '22 04:10

Jwalin Shah