Created
December 12, 2013 19:32
-
-
Save sstur/7933983 to your computer and use it in GitHub Desktop.
String splice similar to array.splice:
stringSplice('abcdef', 2, 2, '_') //=> ab_ef
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stringSplice(source, index, deleteChars, insert) { | |
insert = insert || ''; | |
return source.slice(0, index) + insert + source.slice(index + Math.abs(deleteChars)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment