JavaScript – Remove First Character of String

To remove first character of the given string in JavaScript, call slice() method on the string, and pass 1 as argument to it.

slice() method takes the starting position of the required resulting string as argument, and slices the string.

The syntax of the expression to remove the first character from the string str using slice() method is

</>
Copy
str.slice(1)

slice() returns the resulting sliced string, and does not modify the original string.

Examples

In the following example, we take a string str, remove the first character using slice() method, and display the original and resulting string in pre#output.

index.html

<!DOCTYPE html>
<html lang="en">
<body>
    <pre id="output"></pre>
    <script>
        var str = 'a12345678';
        var result = str.slice(1);
        var output = 'Original string : ' + str;
        output += '\n\nResult string   : ' + result;
        document.getElementById('output').innerHTML = output;
    </script>
</body>
</html>

Conclusion

In this JavaScript Tutorial, we learned how to remove the first character of given string in JavaScript, using slice() method, with examples.