1var a = "I want apple";
2var b = " an";
3var position = 6;
4var output = [a.slice(0, position), b, a.slice(position)].join('');
5console.log(output);
1function addStr(str, index, stringToAdd){
2 return str.substring(0, index) + stringToAdd + str.substring(index, str.length);
3}
4
5let str = "This is a string";
6let stringToAdd = "modyfied ";
7
8console.log(addStr(str, 10, stringToAdd)); //outPut : "This is a modified string"
9
1int j = 123456;
2String x = Integer.toString(j);
3x = x.substring(0, 4) + "." + x.substring(4, x.length);
4
5//output : 1234.56
1let givenString = 'vivekgupta';
2let insertAtPosition = 5;
3let stringToInsert = ' ';
4
5let arrGivenString = [...givenString];
6arrGivenString.splice(insertAtPosition, 0, stringToInsert);
7
8let output = arrGivenString.join('');
9console.log(output);