Javascript Reference - JavaScript String Reference








A JavaScript string stores a series of characters like "tutorial from java2s.com".

A string can be any text inside double or single quotes.

The characters in String are zero-based indexed: The first character is in position 0, the second in 1, and so on.

String Properties

Property Description
constructor Create a string object
length Returns the length of a string
prototype Add properties and methods to an object




String Methods

Method Description
charAt() Get the character by index
charCodeAt() Get the Unicode of the character by index
concat() Add two or more strings together
fromCharCode() Converts Unicode values to characters
indexOf() Search the first found occurrence of sub string
lastIndexOf() Search the last occurrence of a sub string
localeCompare() Compares two strings in the current locale
match() Pattern match a string and returns the matches
replace() Searches a string for a specified value, or a regular expression, and returns a new string
search() Searches a string for a specified value, or regular expression, and returns the position of the match
slice() Extracts a sub string and returns a new string
split() Splits a string into an array of substrings
substr() Get sub string
substring() Get the characters from a string, between two specified indices
toLocaleLowerCase() Converts a string to lowercase letters, according to the host's locale
toLocaleUpperCase() Converts a string to uppercase letters, according to the host's locale
toLowerCase() Converts a string to lowercase letters
toString() Returns the value of a String object
toUpperCase() Converts a string to uppercase letters
trim() Removes whitespace from both ends of a string
valueOf() Returns the primitive value of a String object




String HTML Wrapper Methods

Method Description
anchor() Creates an anchor
big() Render a string using a big font
blink() Render a blinking string
bold() Render a string in bold
fixed() Show a string using a fixed-pitch font
fontcolor() Show a string using a specified color
fontsize() Render a string using a specified size
italics() Show a string in italic
link() Show a string as a hyperlink
small() Show a string using a small font
strike() Show a string with a strikethrough
sub() Show a string as subscript text
sup() Show a string as superscript text