String.prototype.splice = function(idx, rem, str) { return this.slice(0, idx) + str + this.slice(idx + Math.abs(rem)); }; var result = "foo baz".splice(4, 0, "bar "); document.body.innerHTML = result; // "foo bar baz"