-1
How to insert a character at a given position of a string?
Ex: I have the string "abcdefg"
and I want to add ,
before the "f"
to stay "abcde,fg"
, how to do this?
-1
How to insert a character at a given position of a string?
Ex: I have the string "abcdefg"
and I want to add ,
before the "f"
to stay "abcde,fg"
, how to do this?
1
Here’s an example of how to do this:
var a = "abcdefg";
var b = ",";
var position = 5;
var output = [a.slice(0, position), b, a.slice(position)].join('');
console.log(output);
Browser other questions tagged javascript string
You are not signed in. Login or sign up in order to post.
What have you tried so far? Show us some code
– absentia