How to Delete the First Character of a String in JavaScript
You can use a bunch of JavaScript methods to remove the first character of a string. Let’s see what they are and choose the one suited for your case.
slice()
The slice() method extracts the section of a string and returns the extracted part in a brand new string. If you want to delete the first character of a string then you should specify the start index from which the string needs to be extracted:
The slice() method can be used to delete first N characters from the string:
substring()
The substring() is a built-in function in JavaScript which is used to return the part of the given string from starting index to end index. Indexing starts from zero (0):
The substing() method can also be used to remove first N characters from the string:
substr()
The substr() method extracts the part of a string, starting at the character at the specified position, and returns the specified N of characters:
The substr() and substring() methods differ. The substr() method can accept a negative starting position as an offset from the end of the string, while the substring does not. However, the substr() method may be deprecated in future.