How to remove the first character of a string in Javascript

If you want to remove the first character of a string in Javascript, use the "substring" method like this .substring(1).

In the "substring" method, the second parameter is optional. If you don't include a second parameter then it just extracts the rest of the string.

The required parameter, in our case the "1" (.substring(1)) says to start the extraction from index 1, thereby eliminating the first character at index 0.

Example:


let x = "This is a string"
x = x.substring(1);
console.log(x); // "his is a string"

Remove first x number of chars in a String

You can use this pattern to extract the first X number of characters of a string. For example, to remove the first 5 characters just do .substring(5).

Example:


let x = "This is a string"
x = x.substring(5);
console.log(x); // "is a string"

Want to learn how to code and make money online? Check out CodingPhase (referral link)