This may duplicate with previous topics but I can't find what I really need.
I want to get a first three characters of a string. For example:
var str = '012123';
console.info(str.substring(0,3)); //012
I want the output of this string '012' but I don't want to use subString or something similar to it because I need to use the original string for appending more characters '45'. With substring it will output 01245 but what I need is 01212345.
substring
will return a new string012
, butstr
will still be equal to012123
.substring
will not change the contents ofstr
..substring()
(or.slice()
or.substr()
) doesn't change the original string at all, it returns a new string.str
doesn't change unless you explicitly overwrite it withstr = str.substring(0,3)
.strFirstThree = str.substring(0,3)
and still have access tostr
in its entirety.