Answers for "javascript add character to string at position"

2

js insert string at position

var a = "I want apple";
var b = " an";
var position = 6;
var output = [a.slice(0, position), b, a.slice(position)].join('');
console.log(output);
Posted by: Guest on April-13-2020
1

javascript add string to middle of string

function addStr(str, index, stringToAdd){
  return str.substring(0, index) + stringToAdd + str.substring(index, str.length);
}

let str = "This is a string";
let stringToAdd = "modyfied ";

console.log(addStr(str, 10, stringToAdd));  //outPut : "This is a modified string"
Posted by: Guest on September-10-2020
2

add char in specific index stirng javascript

int j = 123456;
String x = Integer.toString(j);
x = x.substring(0, 4) + "." + x.substring(4, x.length);

//output : 1234.56
Posted by: Guest on June-16-2020
0

javascript add character to string at position

let givenString = 'vivekgupta';
let insertAtPosition = 5;
let stringToInsert = ' ';

let arrGivenString = [...givenString];
arrGivenString.splice(insertAtPosition, 0, stringToInsert);

let output = arrGivenString.join('');
console.log(output);
Posted by: Guest on June-01-2021

Code answers related to "javascript add character to string at position"

Code answers related to "Javascript"

Browse Popular Code Answers by Language