Open In App

JavaScript String Methods

Last Updated : 14 Aug, 2025
Comments
Improve
Suggest changes
13 Likes
Like
Report

JavaScript provides a variety of built-in methods to work with strings — allowing you to extract, modify, search, and format text with ease. Below are some of the most commonly used core string methods:

slice()

slice() extracts a part of the string based on the given stating-index and ending-index and returns a new string.


Output
Geeks
for
Geeks

substring()

substring() returns the part of the given string from the start index to the end index. Indexing starts from zero (0).


Output
Power

substr()

substr() This method returns the specified number of characters from the specified index from the given string. It extracts a part of the original string.


Output
Power

replace()

replace() replaces a part of the given string with another string or a regular expression. The original string will remain unchanged.


Output
Mind, Space, Soul

replaceAll()

replaceAll() returns a new string after replacing all the matches of a string with a specified string or a regular expression. The original string is left unchanged after this operation.


Output
Mind, Space, Space, Soul

toUpperCase()

toUpperCase() converts all the characters present in the String to upper case and returns a new String with all characters in upper case. This method accepts single parameter stringVariable string that you want to convert in upper case.


Output
STANDS-FOR-GEEKSFORGEEKS

toLowerCase()

toLowerCase() converts all the characters present in the so lowercase and returns a new string with all the characters in lowercase.


Output
stands-for-geeksforgeeks

concat()

concat() combines the text of two strings and returns a new combined or joined string. To concatenate two strings, we use the concat() method on one object of string and send another object of string as a parameter. This method accepts one argument. The variable contains text in double quotes or single quotes.


Output
GFG stands for GeeksforGeeks

trim()

trim() is used to remove either white spaces from the given string. This method returns a new string with removed white spaces. This method is called on a String object. This method doesn't accept any parameter.


Output
7
3

trimStart()

trimStart() removes whitespace from the beginning of a string. The value of the string is not modified in any manner, including any whitespace present after the string.


Output
  Soul
Soul

trimEnd()

trimEnd() removes white space from the end of a string. The value of the string is not modified in any manner, including any white-space present before the string.


Output
Soul  
Soul

padStart()

padStart() pad a string with another string until it reaches the given length. The padding is applied from the left end of the string.


Output
Mind Soul

padEnd()

padEnd() pad a string with another string until it reaches the given length. The padding is applied from the right end of the string.


Output
Soul Power

charAt()

charAt() returns the character at the specified index. String in JavaScript has zero-based indexing.


Output
GeeksforGeeks
GfG is the best platform to learn and
experience Computer Science.
G
s

charCodeAt()

charCodeAt() returns a number that represents the Unicode value of the character at the specified index. This method accepts one argument.


Output
71
115

split()

split() splits the string into an array of sub-strings. This method returns an array. This method accepts a single parameter character on which you want to split the string.


Output
[ 'stands', 'for', 'GeeksforGeeks' ]

More JS String Methods

Below is the JavaScript string functions list:

Instance Methods

Description

at()Find the character at the specified index.
anchor()Creates an anchor element that is used as a hypertext target.
charAt()Returns that character at the given index of the string.
charCodeAt()Returns a Unicode character set code unit of the character present at the index in the string.
codePointAt()Return a non-negative integer value i.e, the code point value of the specified element.
concat()Join two or more strings together in JavaScript.
endsWith()Whether the given string ends with the characters of the specified string or not.
includes()Returns true if the string contains the characters, otherwise, it returns false.
indexOf()Finds the index of the first occurrence of the argument string in the given string.
lastIndexOf()Finds the index of the last occurrence of the argument string in the given string.
localeCompare()Compare any two elements and returns a positive number
match()Search a string for a match against any regular expression.
matchAll()Return all the iterators matching the reference string against a regular expression.
normalize()Return a Unicode normalization form of a given input string.
padEnd()Pad a string with another string until it reaches the given length from rightend.
padStart()Pad a string with another string until it reaches the given length from leftend.
repeat()Build a new string containing a specified number of copies of the string.
replace()Replace a part of the given string with some another string or a regular expression
replaceAll()Returns a new string after replacing all the matches of a string with a specified string/regex.
search()Search for a match in between regular expressions and a given string object.
slice()Return a part or slice of the given input string.
split()Separate given string into substrings using a specified separator provided in the argument.
startsWith()Check whether the given string starts with the characters of the specified string or not.
substr()Returns the specified number of characters from the specified index from the given string.
substring()Return the part of the given string from the start index to the end index.
toLowerCase()Converts the entire string to lowercase.
toLocaleLowerCase()Returns the calling string value converted to a lowercase letter.
toLocaleUpperCase()Returns the calling string value converted to a uppercase letter.
toUpperCase()Converts the entire string to uppercase.
toString()Return the given string itself.
trim()Remove the white spaces from both ends of the given string.
trimEnd()Remove white space from the end of a string.
trimStart()Remove white space from the start of a string.
valueOf()Return the value of the given string.
string[Symbol.iterator]()This method is used to make String iterable. [@@iterator]() returns an iterator object which iterates over all code points of the String.
fromCharCode(n1, n2, ..., nX)This method is used to create a string from the given sequence of UTF-16 code units. This method returns a string, not a string object.
fromCodePoint(a1, a2, a3, ....)This method in JavaScript that is used to return a string or an element for the given sequence of code point values (ASCII value).
isWellFormed()This method is used to check if the string contains a lone surrogate or not
String.raw(str, ...sub)This is a static method that is used to get the raw string form of template literals. These strings do not process escape characters.
toWellFormed()This method is used to return where all lone surrogates of this string are replaced with the Unicode replacement character.

Also Check


Strings in JavaScript
Visit Course explore course icon

Similar Reads