DEV Community

Pritom Deb
Pritom Deb

Posted on

Important string methods

1. concat(str1, str2, ... , strN)
The concat() method joins two or more strings. The concat() method does not change the existing strings. The concat() method returns a new string.
Image description

2. endsWith(searchString, length)
Checks whether a string ends with specified string/characters. It only returns true or false. The endsWith() method is case sensitive.
Image description

3. includes(searchString, position)
Checks whether a string contains the specified string/characters. It only returns true or false. The includes() method is case sensitive.
Image description

4. indexOf(searchValue, fromIndex)
Returns the position of the first found occurrence of a specified value in a string. The indexOf() method returns -1 if the value is not found. The indexOf() method is case sensitive.
Image description

5. lastIndexOf(searchValue, fromIndex)
Returns the position of the last found occurrence of a specified value in a string. The indexOf() method returns -1 if the value is not found. The lastIndexOf() method is case sensitive.
Image description

6. replace(regexp/substr, newSubstr/replacerFunction)
Searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.
Image description

7. slice(beginIndex, endIndex)
Extracts a part of a string and returns a new string.
Image description

8. split(separator, limit)
Splits a string into an array of substrings. If (" ") is used as separator, the string is split between words.
Image description

9. startsWith(searchString, position)
Checks whether a string begins with specified characters. It only returns true or false. The startsWith() method is case sensitive.
Image description

10. toLocaleLowerCase()
Converts a string to lowercase letters, according to the host's locale. The locale is based on the language settings of the browser. The toLocaleLowerCase() returns the same result as toLowerCase(), except for locales that conflict with the regular Unicode case mappings (such as Turkish).
Image description

11. toLocaleUpperCase()
Converts a string to uppercase letters, according to the host's locale. The locale is based on the language settings of the browser. The toLocaleUpperrCase() returns the same result as toLowerCase(), except for locales that conflict with the regular Unicode case mappings (such as Turkish).
Image description

12. toLowerCase()
Converts a string to lowercase letters.
Image description

13. toLowerCase()
Converts a string to uppercase letters.
Image description

Top comments (0)