How to remove N characters from a string by index in JavaScript

1 Answer

0 votes
function removeNAt(s, i, n) {
    return s.slice(0, i) + s.slice(i + n);
}
   
let s = "javascript php c++";

idx = 3
   
s = removeNAt(s, idx, 4);
   
console.log(s);
  
  
  
   
/*
run:
   
javipt php c++
  
*/

 



answered Jun 20, 2020 by avibootz
edited Jun 21, 2020 by avibootz

Related questions

1 answer 143 views
2 answers 229 views
1 answer 164 views
1 answer 191 views
...