How to insert string at specific index of another string in TypeScript

1 Answer

0 votes
let str = "TypeScript Python C";
const string = 'C++';

const index = 11;

str = str.slice(0, index) + string + str.slice(index);

console.log(str);
 
 
 
 
/*
run:
 
"TypeScript C++Python C"
 
*/

 



answered May 1, 2022 by avibootz
...