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 120 views
2 answers 140 views
2 answers 154 views
1 answer 173 views
1 answer 129 views
1 answer 101 views
...