Easy Tutorial
❮ Prop Style Whitespace Prop Embed Height ❯

JavaScript String Object


String Object

The String object is used to manipulate text (strings).

To create a String object: new String().

Syntax

Alternatively, a simpler way:

To learn more about the String object, please refer to the JavaScript String Object Tutorial.


String Object Properties

Property Description
constructor A reference to the function that created the object
length The length of the string
prototype Allows you to add properties and methods to the object

String Object Methods

Method Description
charAt() Returns the character at the specified position
charCodeAt() Returns the Unicode of the character at the specified position
concat() Joins two or more strings and returns a new string
endsWith() Checks if the string ends with the specified substring (case-sensitive)
fromCharCode() Converts Unicode values to characters
indexOf() Returns the position of the first occurrence of a specified value in a string
includes() Checks if a string contains the specified substring
lastIndexOf() Searches the string from the end to the beginning and returns the last occurrence of the specified substring
match() Searches a string for a match against a regular expression
repeat() Returns a new string with a specified number of copies of the original string
replace() Searches a string for a match against a substring, and replaces the matched substring
replaceAll() Searches a string for all matches against a substring, and replaces all matched substrings
search() Searches a string for a match against a regular expression
slice() Extracts a part of a string and returns the extracted part in a new string
split() Splits a string into an array of substrings
startsWith() Checks if a string begins with the specified substring
substr() Extracts a specified number of characters from a string, starting from a specified position
substring() Extracts characters from a string between two specified indices
toLowerCase() Converts a string to lowercase letters
toUpperCase() Converts a string to uppercase letters
trim() Removes whitespace from both ends of a string
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
valueOf() Returns the primitive value of a String object
toString() Returns a string

String HTML Wrapper Methods

HTML wrapper methods return the string wrapped in the corresponding HTML tag.

Note that these methods are not standard and may not be supported in all browsers.

Method Description
anchor() Creates an HTML anchor
big() Displays a string in a large font
blink() Displays a blinking string
bold() Displays a string in bold
fixed() Displays a string in monospace font
fontcolor() Displays a string in the specified color
fontsize() Displays a string in the specified size
italics() Displays a string in italic
link() Displays a string as a hyperlink
small() Displays a string in a small font
strike() Displays a string with a strikethrough
sub() Displays a string as subscript
sup() Displays a string as superscript
❮ Prop Style Whitespace Prop Embed Height ❯