It’s Festive Season! Enjoy 30% Off

Use code FESTIVE30 at checkout

Code has been added to clipboard!

String Functions

Reading time 3 min
Published Aug 9, 2017
Updated Oct 10, 2019

JavaScript String Functions: Main Tips

  • Strings in JavaScript are a data type for storing character sequences.
  • Strings can be modified with a variety of JavaScript string functions: replace(), search(), substr() and many more.
  • JavaScript strings are a primitive data type but can still access various methods and properties.

List of Properties

The JavaScript string object contains several properties. By using them, you can get information on the string or provide some additional features.

For instance, the length will indicate how long the string is, and the constructor reveals the constructor of the string.

The table below explains all of the possible properties:

Property Description
constructor Return string's constructor function.
length Return length of string.
prototype Add properties and methods to object.

Common String Methods

The string manipulation is completed with JavaScript string functions for modifying, deleting, organizing, or replacing entire strings or their portions.

The variety of methods allows you to arrange strings into arrays or to extract a specific portion of the string as well.

In the table below, we provide a brief introduction to the JavaScript string functions.

Some of these functions have their own separate tutorials prepared as well. You can read more about string.includes(), replace(), slice(), splice(), and others.

Method Description
charAt() Return character at specified index (position).
charCodeAt() Return Unicode of the character at specified index.
concat() Join multiple strings, and return new joined ones.
endsWith() Check whether a string ends with specified string/characters.
fromCharCode() Convert Unicode values to characters.
includes() Check whether string contains specified string/characters.
indexOf() Return position of the first found occurrence of specified value in string.
lastIndexOf() Return position of last found occurrence of specified value in string.
localeCompare() Compare two strings in current locale.
match() Search string for matches against regular expression, and return those matches.
repeat() Return new string with specified number of copies of existing string.
replace() Search string for specified value, or regular expression, and a return new string where specified values are replaced.
search() Search string for specified value, or regular expression, and return position of match.
slice() Extract part of string and return new string.
split() Split string into array of substrings.
startsWith() Check whether a string begins with specified characters.
substr() Extract characters from string, beginning at specified start position, and through specified number of characters.
substring() Extract characters from string, between two specified indices.
toLocaleLowerCase() Convert string to lowercase letters, according to host's locale.
toLocaleUpperCase() Convert string to uppercase letters, according to host's locale.
toLowerCase() Convert string to lowercase letters.
toString() Return value of string object.
toUpperCase() Convert string to uppercase letters.
trim() Remove whitespace from both ends of string.
valueOf() Return primitive value of String object.

Description of HTML Wrapper Methods

The HTML wrapper methods return the string enclosed within the appropriate HTML tag. In other words, you can manipulate the JavaScript string format.

After you create a new string, you link a string object to it as well.

Due to the string object, you can select from a variety functions to manage the JavaScript string format. The following table consists of methods that can be applied to change format of strings:

Method Description
anchor() Create anchor.
big() Display string in a bigger font
blink() Display a blinking string
bold() Display string in bold
fixed() Display string using fixed-pitch font
fontcolor() Display string using a defined color
fontsize() Display string using a defined size
italics() Display string in italic
link() Display string as hyperlink
small() Display string in a smaller font
strike() Display string with strikethrough
sub() Display string as subscript text
sup() Display string as superscript text