JavaScript strings are
used for storing and manipulating text.
A JavaScript string
simply stores a series of characters like "John Doe".
A string can be any
text inside quotes. You can use single or double quotes:
String Length
The length of a string is found in
the built in property length:
Example
Special Characters
Because strings must
be written within quotes, JavaScript will misunderstand this string:
Example
String Methods
Method
|
Description
|
charAt()
|
Returns
the character at the specified index (position)
|
charCodeAt()
|
Returns
the Unicode of the character at the specified index
|
concat()
|
Joins
two or more strings, and returns a copy of the joined strings
|
fromCharCode()
|
Converts
Unicode values to characters
|
indexOf()
|
Returns
the position of the first found occurrence of a specified value in a string
|
lastIndexOf()
|
Returns
the position of the last found occurrence of a specified value in a string
|
localeCompare()
|
Compares
two strings in the current locale
|
match()
|
Searches
a string for a match against a regular expression, and returns the matches
|
replace()
|
Searches
a string for a value and returns a new string with the value replaced
|
search()
|
Searches
a string for a value and returns the position of the match
|
slice()
|
Extracts
a part of a string and returns a new string
|
split()
|
Splits a
string into an array of substrings
|
charAt() Example
charCodeAt() Example
concat() Example
lastIndexOf() Example