How can I remove the first three letters of a string in JQuery?
For example: Turn cat1234
to 1234
How can I remove the first three letters of a string in JQuery?
For example: Turn cat1234
to 1234
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));
var val = 'cat1234';
var newVal = val.substring(3, val.length);
You don't need jQuery to do this, JavaScript will do:
"cat1235".substring(3) // yields 1235
You don't have to use jquery to do that, use simple javascript:
var txt = 'cat1234';
var txt2 = txt.substr(3);
function trimCat() { return "cat1234".substring(3, 6); }
or
function trimAnotherCat() { return "cat1234".replace("cat", ""); }
var cat1234 = 'cat1234';
var new1234 = cat1234.substring(3);
JavaScript can do the trick.
var s = 'cat1234';
console.log(s.toString().slice(3));
This will output: 1234
var str = 'cat1234';
var newStr = str.slice(3);
it works for me. slice(3)
will slice first 3 character from string.