To remove the first N characters of a string in JavaScript, you can use the slice method starting from index N.
In this example,
str1
with a value of "Hello World"
.let str1 = 'Hello World';
let result = str1.slice(3);
console.log('Modified string is: ' + result);
Modified string is: lo World
In this example,
str2
with a value of "apple"
.let str2 = 'apple';
let result = str2.slice(2);
console.log('Modified string is: ' + result);
Modified string is: ple
In this tutorial, we learned How to Remove first N Characters in a String in JavaScript language with well detailed examples.