JavaScript String Object

The String is a built-in object in JavaScript that allows you to represent data in text form.

In JavaScript, strings are both the primitive data type and the object. JavaScript automatically converts the primitive string into the String object. Hence, you can access the methods and property of the String object for the primitive string. For example, the length property can be used to get the number of characters in a string.

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