How to replace the first N characters in a string in JavaScript

1 Answer

0 votes
let str = 'javascript';
 
const N = 3; 
str = 'XYZ' + str.slice(N);
 
console.log(str);
 
 
   
   
   
   
/*
run:
 
"XYZascript"
   
*/

 



answered Jun 12, 2022 by avibootz

Related questions

1 answer 220 views
2 answers 273 views
2 answers 276 views
1 answer 278 views
1 answer 217 views
1 answer 202 views
...