how can i remove chars between indexes in a javascript string -
i have following:
var s="hi how you"; var bindex = 2; var eindex = 6;
how can remove chars s reside between bindex , eindex?
therefore s "hi you"
first find substring of string replace, replace first occurrence of string empty string.
s = s.replace(s.substring(bindex, eindex), "");
another way convert string array, splice
out unwanted part , convert string again.
var result = s.split(''); result.splice(bindex, eindex - bindex); s = result.join('');
Comments
Post a Comment