Generating serial numbers with adding String at middle using Javascript

I wrote one JavaScript/jQuery plugin to one of my client. In that, generating serial numbers with adding string at middle is one of the concept. Concept was, want to place the custom string value at positions but remaining values should aligned serial. For Example: serial Values is “1,2,3,4,5,6”,¬†¬†want to place a string “D” at 2 positions 3 & 2. So finally result should be, 1,D,2,D,3,4.

How to achieve this?

Here is the quick JavaScript code which i got on stack-overflow site. It was done using JavaScript.

var deletedString = "4,2";
var deletearray = SplitString_ToArray(deletedString);
deletedString = deletearray.toString();
var Values = "1,2,3,4,5,6";
var allValues = Values.split(','),
 length = allValues.length;

deletedString.split(',').forEach(function(position) {
 allValues.splice(parseInt(position) - 1, 0, 'D');

var newValues = allValues.splice(0, length).join();

function sortfunction(a, b){
return (a - b) //causes an array to be sorted numerically and ascending

function SplitString_ToArray(inString){
 var result = inString.split(',');
 return result;

JsFiddle DEMO