Categories
JavaScript Answers

How to get first three characters of a string with JavaScript?

Spread the love

Sometimes, we want to get first three characters of a string with JavaScript.

In this article, we’ll look at how to get first three characters of a string with JavaScript.

How to get first three characters of a string with JavaScript?

To get first three characters of a string with JavaScript, we can use the string substring method.

For instance, we write

const str = "012123";
const strFirstThree = str.substring(0, 3);

console.log(strFirstThree);

to call str.substring with 0 and 3 to return a string with the first 3 characters of str.

Conclusion

To get first three characters of a string with JavaScript, we can use the string substring method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.