JavaScript String Methods
Strings are texts that aid in the storage of data that may be expressed. A JavaScript string contains a string of characters such as "Welcome To WebTutor." A string is any text enclosed in double or single quotations.
Syntax
String indexes begin at 0. The first character is in place 0, the second in position 1, and so on. We may call any of JavaScript's pre-defined methods since it automatically transforms string primitives to objects.
1. String length
A string's length is returned by the length property.
2. String slice()
Extracts a section of a string and returns a new string.
3. String substring()
Extracts a section of a string between two specified indices and returns a new string.
4. String substr()
Extracts a section of a string starting from a specified index and returns a new string.
5. String replace()
Searches a string for specified characters and replaces them with new characters.
6. String replaceAll()
In place of the string to be replaced, you can supply a regular expression using the replaceAll() function. Must be global flag (g), JavaScript string set if parameter is regular expression; Otherwise, a TypeError is raised.
7. String toUpperCase()
Converts a string to uppercase.
8. String toLowerCase()
Converts a string to lowercase.
9. String concat()
Joins two or more strings and returns a new string.
10. String trim()
Removes whitespace from both ends of a string.
11. String trimStart()
Removes whitespace from the beginning of a string.
12. String trimEnd()
Removes whitespace from the end of a string.
13. String padStart()
Pads the beginning of a string with specified characters.
14. String padEnd()
Pads the end of a string with specified characters.
15. String charAt()
Returns the character at a specified index in a string.
16. String charCodeAt()
Returns the Unicode of the character at a specified index in a string.
17. String split()
Splits a string into an array of substrings based on specified characters.
18. String search()
Searches a string for specified characters and returns the index of the first occurrence.
19. String match()
Searches a string for specified characters and returns an array of matches.
20. String matchAll()
Returns an iterator of all matches of a regular expression in a string.
21. String includes()
Checks whether a string contains specified characters or not.
22. String startsWith()
Checks whether a string starts with specified characters or not.
23. String endsWith()
Checks whether a string ends with specified characters or not.
24. String indexOf()
The index of (position of) the first instance of a string in a string is returned by the indexOf() function.
25. String lastIndexOf()
The lastIndexOf() function returns the string's string's index for the final instance of the provided text.