JavaScript String Complete Reference
JavaScript strings are used for storing and manipulating text content. It can contain zero or more characters within single or double quotes, like “Geeksforgeeks” or ‘Geeksforgeeks’.
Syntax:
String(object)
Example: Return Date() object’s string value
HTML
<!DOCTYPE html><html> <body> <center> <h1 style="color:green;"> GeeksforGeeks </h1> <button onclick="geek()"> Press </button> <h4> Clicking on the 'Press' button will return the String Value. </h4> <p id="gfg"></p> <script> function geek() { var y = Date(); var string = String(y); document.getElementById("gfg").innerHTML = string; } </script> </center> </body></html> |
Output:

The complete list of JavaScript String properties and methods are listed below:
Properties:
JavaScript String Instance Properties | Description |
|---|---|
| JavaScript String length Property | The length property of the JavaScript object is used to find out the size of that object |
| JavaScript String constructor Property | The String constructor property in JavaScript is used to return the string constructor function for the object. |
Methods:
JavaScript String Instance Methods | Description |
|---|---|
| JavaScript String() Method | The String() function is used to convert an anchor element from the value of an object to a string value. |
| JavaScript String anchor() Method | The anchor() method creates an anchor element that are used as a hypertext target |
| JavaScript String charAt() Method | JavaScript str.charAT() Returns the thatcharacter at the given index of the string. |
| JavaScript String charCodeAt() Method | str.charCodeAt() method returns a Unicode character set code unit of the character present at the index in the string specified as the argument. |
| JavaScript String codePointAt() Method | The string.codePointAt() is an inbuilt method in JavaScript which is used to return a non-negative integer value i.e, the thatcode point value of the specified element of the given string. |
| JavaScript String concat() Method | JavaScript str.concat() function is used to join two or more strings together in JavaScript. |
| JavaScript String endsWith() Method | JavaScript str.endsWith() function is used to check whether the given string ends with the characters of the specified string or not |
| JavaScript String fromCharCode() Method | JavaScript String.fromCharCode() method is used to create a string from the given sequence of UTF-16 code units. |
| JavaScript String fromCodePoint() Method | The String.fromCodePoint() is an inbuilt method in JavaScript which is used to return a string or an element for the given sequence of code point values (ASCII value). |
| JavaScript String includes() Method | In JavaScript, the includes() method determines whether a string contains the given characters within it or not. This method returns true if the string contains the characters, otherwise, it returns false. |
| JavaScript String indexOf() Method | JavaScript str.lastIndexOf() method finds the index of the last occurrence of the argument string in the given string. The value returned is 0-based. |
| JavaScript String lastIndexOf() Method | JavaScript str.lastIndexOf() method finds the index of the last occurrence of the argument string in the given string. The value returned is 0-based. |
| JavaScript String localeCompare() Method | The string.localeCompare() is an inbuilt method in JavaScript which is used to compare any two elements and returns a positive number |
| JavaScript String match() Method | The string.match() is an inbuilt function in JavaScript used to search a string for a match against any regular expression. |
| JavaScript String normalize() Method | The string.normalize() is an inbuilt method in javascript which is used to return a Unicode normalization form of a given input string. |
| JavaScript String padEnd() Method | The padEnd() method in JavaScript is used to pad a string with another string until it reaches the given length. The padding is applied from the right end of the string. |
| JavaScript String padStart() Method | The padStart() method in JavaScript is used to pad a string with another string until it reaches the given length. The padding is applied from the left end of the string. |
| JavaScript String repeat() Method | The string.repeat() is an inbuilt function in JavaScript that is used to build a new string containing a specified number of copies of the string on which this function has been called. |
| JavaScript String replace() Method | The string.replace() is an inbuilt method in JavaScript that is used to replace a part of the given string with some another string or a regular expression |
| JavaScript String replaceAll() Method | The replaceAll() method returns a new string after replacing all the matches of a string with a specified string or a regular expression. |
| JavaScript String search() Method | The string.search() method is the inbuilt method in JavaScript that is used to search for a match in between regular expressions and a given string object. |
| JavaScript String slice() Method | The string.slice() is an inbuilt method in javascript that is used to return a part or slice of the given input string. |
| JavaScript String split() Method | JavaScript str.split() method is used to split the given string into an array of strings by separating it into substrings using a specified separator provided in the argument. |
| JavaScript String startsWith() Method | The str.startsWith() method is used to check whether the given string starts with the characters of the specified string or not. |
| JavaScript String substr() Method | JavaScript str.substr() method returns the specified number of characters from the specified index from the given string. |
| JavaScript String substring() Method | The string.substring() is an inbuilt function in JavaScript that is used to return the part of the given string from the start index to the end index. Indexing starts from zero (0). |
| JavaScript String toLowerCase() Method | str.toLowerCase() method converts the entire string to lowercase. This method does not affect any of the special characters, digits, and the alphabet that are already in lowercase. |
| JavaScript String toUpperCase() Method | str.toUpperCase() method converts the entire string to Upper case. This method does not affect any of the special characters, digits, and the alphabets that are already in the upper case. |
| JavaScript String toString() Method | The string.toString() is an inbuilt method in JavaScript that is used to return the given string itself. |
| JavaScript String trim() Method | JavaScript String trim() method is used to remove the white spaces from both ends of the given string. |
| JavaScript String trimEnd() Method | The trimEnd() method in JavaScript is used to remove white space from the end of a string. |
| JavaScript String trimStart() Method | The trimEnd() method in JavaScript is used to remove white space from the end of a string. |
| JavaScript String includes() Method | In JavaScript, the includes() method determines whether a string contains the given characters within it or not. |
| JavaScript String valueOf() Method | The string.valueOf() is an inbuilt method in JavaScript which is used to return the value of the given string. |






Please Login to comment...