Categories
JavaScript Answers

How to remove part of a string with JavaScript?

Spread the love

Sometimes, we want to remove part of a string with JavaScript.

In this article, we’ll look at how to remove part of a string with JavaScript.

How to remove part of a string with JavaScript?

To remove part of a string with JavaScript, we call the string substring method.

For instance, we write

const str = "test_23";
alert(str.substring("test_".length));

to call str.substring with the starting index of the str string to return.

Then the alert box should show '23'.

Conclusion

To remove part of a string with JavaScript, we call the string substring method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *