Skip to content
Related Articles

Related Articles

JavaScript String Complete Reference

Improve Article
Save Article
  • Last Updated : 23 Nov, 2022
Improve Article
Save Article

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 PropertyThe length property of the JavaScript object is used to find out the size of that object
JavaScript String constructor PropertyThe String constructor property in JavaScript is used to return the string constructor function for the object.

Methods:

JavaScript String Instance Methods

Description

JavaScript String() MethodThe String() function is used to convert an anchor element from the value of an object to a string value.
JavaScript String anchor() MethodThe anchor() method creates an anchor element that are used as a hypertext target 
JavaScript String charAt() MethodJavaScript str.charAT() Returns the thatcharacter at the given index of the string.
JavaScript String charCodeAt() Methodstr.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() MethodThe 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() MethodJavaScript str.concat() function is used to join two or more strings together in JavaScript.
JavaScript String endsWith() MethodJavaScript str.endsWith() function is used to check whether the given string ends with the characters of the specified string or not
JavaScript String fromCharCode() MethodJavaScript String.fromCharCode() method is used to create a string from the given sequence of UTF-16 code units.
JavaScript String fromCodePoint() MethodThe 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() MethodIn 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() MethodJavaScript 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() MethodJavaScript 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() MethodThe string.localeCompare() is an inbuilt method in JavaScript which is used to compare any two elements and returns a positive number
JavaScript String match() MethodThe string.match() is an inbuilt function in JavaScript used to search a string for a match against any regular expression. 
JavaScript String normalize() MethodThe 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() MethodThe 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() MethodThe 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() MethodThe 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() MethodThe 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() MethodThe 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() MethodThe 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() MethodThe 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() MethodJavaScript 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() MethodThe str.startsWith() method is used to check whether the given string starts with the characters of the specified string or not. 
JavaScript String substr() MethodJavaScript str.substr() method returns the specified number of characters from the specified index from the given string.
JavaScript String substring() MethodThe 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() Methodstr.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() Methodstr.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() MethodThe string.toString() is an inbuilt method in JavaScript that is used to return the given string itself.
JavaScript String trim() MethodJavaScript String trim() method is used to remove the white spaces from both ends of the given string.
JavaScript String trimEnd() MethodThe trimEnd() method in JavaScript is used to remove white space from the end of a string. 
JavaScript String trimStart() MethodThe trimEnd() method in JavaScript is used to remove white space from the end of a string.
JavaScript String includes() MethodIn JavaScript, the includes() method determines whether a string contains the given characters within it or not.
JavaScript String valueOf() MethodThe string.valueOf() is an inbuilt method in JavaScript which is used to return the value of the given string.

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!