Remove First Character from String in JavaScript
Abstract: or to the end of the string. Example var str= "Hello TecAdmin12345 var str = "Hello TecAdmin
Question – How to remove first character of a string using JavaScript ?
In the previous article, you have learned to remote last character of a string in JavaScript. If you are looking for remove last character from string, visit here. This tutorial describe you to how to remove first character of a string in JavaScript. You can choose any one of the following methods.
Method 1 – Using substring() functionUse the substring() function to remove the last character from a string in JavaScript. This function returns the part of the string between the start and end indexes, or to the end of the string.
Example
<script> var str= "Hello TecAdmin!"; var newStr = str.substring(1, str.length); console.log(newStr); </script>12345<script> var str= "Hello TecAdmin!"; var newStr = str.substring(1, str.length); console.log(newStr);</script>Output:
ello TecAdmin!Method 2 – Using slice() function
Use the slice function to remove the last character from any string in JavaScript. This function extracts a part of any string and return as new string. When you can store in a variable.
Example:
<script> var str = "Hello TecAdmin!"; var newStr = str.slice(1); console.log(newStr); </script>12345<script> var str = "Hello TecAdmin!"; var newStr = str.slice(1); console.log(newStr);</script>Output:
ello TecAdmin!Conclusion
In this tutorial, you have learned how to remove first character from a string using JavaScript. You can also read our next tutorial to trim white spaces from string.