JavaScript String Methods

In JavaScript, strings are used to represent and work with a sequence of characters. A string can represent an object as well as the primitive data type. JavaScript automatically converts primitive strings to String objects so that it's possible to use String methods and access properties even for primitive strings.

In this reference page, you will find all String methods and properties available in JavaScript. For example, the toUpperCase() method returns the string converted to uppercase.

JavaScript String length

Returns the number of characters in a string

JavaScript String replace()

replace a substring/pattern in the string

JavaScript String indexOf()

Returns the first index of occurrence of a value

JavaScript String lastIndexOf()

Returns the last index of occurrence of a value

Javascript String startsWith()

Checks if a string begins with a specified string

Javascript String endsWith()

Checks if a string ends with a specified string

Javascript String toUpperCase()

Returns uppercase of a string

Javascript String toLowerCase()

Returns lowercase representation of a string

Javascript String includes()

Checks if given string is found inside a string

JavaScript String repeat()

Returns a string by repeating it given times

JavaScript String charAt()

Returns character at a specified index in string

JavaScript String charCodeAt()

Returns Unicode of the character at given index

JavaScript String fromCharCode()

Returns a string from the given UTF-16 code units

Javascript String substring()

Returns a specified part of the string

Javascript String padStart()

Pads a string at the start to a given length

Javascript String padEnd()

Pads a string at the end to a given length

JavaScript String codePointAt()

Returns the Unicode point value at given index

JavaScript String fromCodePoint()

Returns a string using the given code points

Javascript String match()

Returns result of matching string with a regex

Javascript String matchAll()

Returns iterator of results matching with a regex

Javascript String localeCompare()

Compares two strings in the current locale

Javascript String search()

Searches for specified value in the string

JavaScript String replaceAll()

Returns string by replacing all matching patterns

JavaScript String concat()

Concatenates the arguments to the calling string

JavaScript String split()

Returns the string divided into list of substring

JavaScript String trim()

Removes whitespace from both ends of a string

JavaScript String slice()

Extracts and returns a section of the string