0% completed
JavaScript provides a couple of methods for working with strings, enabling developers to perform manipulations
, searches
, transformations
, and much more. Below is a comprehensive table of string methods available in JavaScript:
Here's a table for the commonly used string property:
Sr.No | Property | Description |
---|---|---|
1 | length | Returns the length of the string. |
Here's an expanded table of string methods including the additional ones as per the tutorial:
Sr.No | Method Name | Description |
---|---|---|
1 | charAt() | Returns the character at the specified index (position). |
2 | charCodeAt() | Returns the Unicode of the character at the specified index. |
3 | concat() | Joins two or more strings, and returns a new joined strings. |
4 | fromCharCode() | Converts Unicode values to characters. |
5 | includes() | Determines whether a string contains a specified string/characters. |
6 | endsWith() | Determines whether a string ends with specified string/characters. |
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 | localeCompare() | Compares two strings in the current locale. |
10 | match() | Searches a string for a match against a regular expression, and returns the matches. |
11 | repeat() | Returns a new string with a specified number of copies of an existing string. |
12 | replace() | Searches a string for a specified value, or a regular expression, and returns a string where the specified values are replaced. |
13 | search() | Searches a string for a specified value, or regular expression, and returns the position of the match. |
14 | slice() | Extracts a part of a string and returns a new string. |
15 | split() | Splits a string into an array of substrings. |
16 | startsWith() | Determines whether a string begins with specified characters. |
17 | substr() | Extracts the characters from a string, beginning at a specified start position, and through the specified number of character. |
18 | substring() | Extracts the characters from a string, between two specified indices. |
19 | toLocaleLowerCase() | Converts a string to lowercase letters, according to the host's current locale. |
20 | toLocaleUpperCase() | Converts a string to uppercase letters, according to the host's current locale. |
21 | toLowerCase() | Converts a string to lowercase letters. |
22 | toUpperCase() | Converts a string to uppercase letters. |
23 | toString() | Returns the value of a String object. |
24 | trim() | Removes whitespace from both ends of a string. |
25 | valueOf() | Returns the primitive value of a String object. |
26 | trimStart() | Removes whitespace from the beginning of a string. |
27 | trimEnd() | Removes whitespace from the end of a string. |
The length
property returns the number of characters in a string, including spaces and special characters.
message.length
evaluates to 13
because the string "Hello, World!"
consists of 13 characters, including punctuation and spaces.The slice()
method extracts a section of a string and returns it as a new string, without modifying the original string. It takes two arguments: the starting index and the ending index (the end index is not included in the result).
text.slice(0, 5)
extracts characters from index 0
to index 5
(not including the character at index 5), resulting in the substring "Hello"
.text
, remains unchanged after the operation.The toUpperCase()
method converts the entire string to uppercase letters. It does not take any arguments and does not modify the original string.
greeting.toUpperCase()
converts "Hello, world!"
to uppercase, resulting in "HELLO, WORLD!"
.Each of these examples demonstrates practical uses of JavaScript string methods and properties, showcasing how they can be applied to manipulate and analyze text data effectively.
.....
.....
.....