Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»Remove First Character from String in JavaScript

    Remove First Character from String in JavaScript

    By RahulMarch 2, 20211 Min Read

    Question – How to remove first character of a string using JavaScript ?

    Advertisement

    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() function

    Use 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

    1
    2
    3
    4
    5
    <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:

    1
    2
    3
    4
    5
    <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.

    javascript js string
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Split Large Archives in Linux using the Command Line

    System.out.println() Method in Java: A Beginner’s Guide

    sleep Command in Linux with Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Split Large Archives in Linux using the Command Line
    • System.out.println() Method in Java: A Beginner’s Guide
    • Split Command in Linux With Examples (Split Large Files)
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.