Based on your follow-up in the comments: use .substring()
and .replace()
, remembering that Javascript (like almost every other language) uses offsets starting at 0, not 1, and reading the substring
function documentation to make sure that its arguments are provided as "start position, inclusive, end position, exclusive":
var a = "jakxxxjakxxx";
var b = "jakxxxjakxxx";
var c = a.replace(a.substring(3,6)); // => "jakjakxxx"
var d = b.replace(a.substring(0,3)); // => "xxxjakxxx"
Done. House that in its own function with argument rewriting if you use it a lot, but to achieve what you want to achieve, you just need two built-ins, but the one thing you should not be doing is trying to make this work with your own personal choice of which numbers indicate which index in a string or a slice: work with the JS conventions, don't bake anti-patterns into your source code.