I want to replace text between two indices in Javascript, something like:
str = \"The Hello World Code!\"; str.replaceBetween(4,9,\"Hi\"); // outputs \"The
There is no such method in JavaScript. But you can always create your own:
String.prototype.replaceBetween = function(start, end, what) { return this.substring(0, start) + what + this.substring(end); }; console.log("The Hello World Code!".replaceBetween(4, 9, "Hi"));