JavaScript offers several ways to remove the first character from a string but you should read this article to avoid using the deprecated one.

Contents

Method #1: slice(startIndex[, endIndex])

The String.prototype.slice() method returns the part of the string between the start (inclusive) and the end (exclusive) indexes or the end of the string if the end index is omitted.

To remove the first character from the string, you need to slice it from the second character whose index is 1. So the start index is 1 and the end index can be omitted.

const string = 'Hello World';
string.slice(1); // 'ello World'

If you want to specify the end index, you totally can. Since the character at the end index is not included, this index should be string.length instead of string.length - 1.

string.slice(1, string.length); // 'ello World'

Method #2: substring(startIndex[, endIndex])

Although the String.prototype.substring() and String.prototype.slice() methods are little different, within the purpose of this article, they are exactly the same.

const string = 'Hello World';
string.substring(1); // 'ello World'
string.substring(1, string.length); // 'ello World'

Method #3: substr(startIndex[, length]) [DEPRECATED]

The String.prototype.substr() method returns the part of the string starting at the start index with the specified length. This method is deprecated so you should avoid using it.

Conclusion

You should only use the first 2 ways to remove the first character from a string and completely ignore the deprecated one.