How to Delete the First Character of a String in JavaScript
Read this tutorial and learn some useful information about the methods that are used for deleting the first character of a string in JavaScript easily.
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:
Javascript slice method
The <kbd class="highlighted">slice()</kbd> method can be used to delete first N characters from the string:
Javascript slice method
substring()
The substring() method 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 <kbd class="highlighted">zero (0)</kbd>:
Javascript substring method
The <kbd class="highlighted">substring()</kbd> method can also be used to remove first N characters from the string:
Javascript substring method
substr()
The <kbd class="highlighted">substr()</kbd> method extracts the part of a string, starting at the character at the specified position, and returns the specified N of characters:
Javascript substr method
The <kbd class="highlighted">substr()</kbd> and <kbd class="highlighted">substring()</kbd> methods differ. The <kbd class="highlighted">substr()</kbd> method can accept a negative starting position as an offset from the end of the string, while the substring does not. However, the <kbd class="highlighted">substr()</kbd> method is officially deprecated in the ECMAScript specification.