All TalkersCode Topics

Follow TalkersCode On Social Media

Remove First Character From String JavaScript

Last Updated : Jan 1, 2023

Remove First Character From String JavaScript

In this tutorial we will show you the solution of remove first character from string JavaScript, we can remove any characters from string using JavaScript inbuilt methods, here we used substring() method.

Using this method, we can remove any characters because it is collects particular character index then it will removes that character from a string so not only first character it can remove any specific character in provided string.

Step By Step Guide On Remove First Character From String JavaScript :-

Here we defined one string ‘Hello’ then using substring() method with value ‘1’ we easily removed first character of provide string ‘H’ will eliminated from that string and stored to variable ‘str’.

The substring() method extracts characters between two indices, from a string and returns the substring.

It will extracts characters from start to end. The substring() method does not change the original string.

<!DOCTYPE html>
        <title>Remove First Character From String</title>
            let str='Hello';
            str = str.substring(1);
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contains information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  5. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  6. Within <script> tag we defined our javascript program, here ‘let’ keyword used for declare a variable ‘str’ with string ‘Hello’ and instead ‘let’ we can also use ‘var’ keyword both are had same behavior.
  7. In substring() method with value ‘1’ refers first character ‘H’ from string ‘Hello’ and it is extracts the ‘H’ from string then remaining sub string ‘ello’ stored to variable ‘str’.
  8. Printed result string using ‘console.log()’ method. Console.log() is a function in javascript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user. Its output display on the javascript console.
  9. In browser for open javascript console use the shortcut ‘ctrl+shift+j’ then console panel will open at right hand side there we can see our result and also we can write and execute any script code there with results.
  10. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion we are able to know how to remove first character from a string using javascript.

When we execute our program on browser we can’t see the result so we have use that shortcut ‘ctrl+shift+j’ then result will see printed on console by console.log().

For print values on webpage in javascript we had many methods and we have methods for remove characters from string like replace(), slice() or string replace().

We will see all these methods in future I hope this tutorial on remove first character from string JavaScript helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials