20 built-in Methods for String Manipulation in JavaScript

JavaScript has several built-in methods for manipulating strings. These methods can be used to perform various tasks such as finding a string within a

·

2 min read

Table of contents

JavaScript has several built-in methods for manipulating strings. These methods can be used to perform various tasks such as finding a string within another string, extracting characters from a string, or converting a string to uppercase or lowercase.

In this post, we will cover some of the most commonly used string methods in JavaScript which are as mentioned below:

  1. charAt() // Returns the character at the specified index

  2. charCodeAt() //Returns the Unicode value of the character at the specified index

  3. concat() //Joins two or more strings and returns a new string

  4. endsWith() //Checks whether a string ends with another string

  5. fromCharCode() //Converts Unicode values to characters

  6. includes() //Checks whether a string contains another string

  7. indexOf() //Returns the position of the first found occurrence of a specified value in a string

  8. lastIndexOf() //Returns the position of the last found occurrence of a specified value in a string

  9. repeat() //Returns a new string with a specified number of copies of an existing string

  10. replace() //Replaces text in a string, and returns a new string

  11. search() //Searches for a specified value in a string, and returns the position of the match

  12. slice() //Extracts parts of a string, and returns the extracted parts in a new string

  13. split() //Splits a string into an array of substrings, and returns the new array

  14. startsWith() //Checks whether a string begins with another string

  15. substr() //Extracts parts of a string, beginning at a specified start index, and returns the new sub-string

  16. substring() //Extracts characters from a string, between two specified indices, and returns the new sub-string

  17. toLowerCase() //Converts a string to lowercase letters

  18. toUpperCase() //Converts a string to uppercase letters

  19. trim() //Removes whitespace from both sides of a string

  20. valueOf() //Returns the primitive value of a string

Summary

In this blog post, we learned about some of the most commonly used string methods in JavaScript. These methods can be used to perform various tasks such as finding a string within another string, extracting characters from a string, or converting a string to uppercase or lowercase.

We hope you found this tutorial helpful. Happy coding!

Did you find this article valuable?

Support Atif Riaz by becoming a sponsor. Any amount is appreciated!