How to add N spaces to middle of string before specific letter in TypeScript

1 Answer

0 votes
let str = 'java javascript c c++ typescript php';
 
const N = 5;

const index = str.indexOf('t');

str = str.slice(0, index) + ' '.repeat(N) + str.slice(index);
 
console.log(str); 
 
    
    
    
    
/*
run:
    
"java javascrip     t c c++ typescript php" 
    
*/

 



answered Apr 26, 2022 by avibootz

Related questions

1 answer 123 views
1 answer 100 views
1 answer 128 views
1 answer 246 views
2 answers 129 views
...