Strings

  • String elements are zero-based.
  • Strings are objects.
  • String literals can be delimited by single or double quotes.
  • String literals are automatically converted to objects.

Properties


length

  • The number of characters in the string.

Methods

 

toLowerCase()
toUpperCase()

charAt(index)

  • Returns the character at the specified index.

indexOf(search-str)

  • Returns the index number of the first occurrence of the search string (searches from left to right), or -1 if the string is not found.

lastIndexOf(search-str)

  • Returns the index number of the last occurrence of the search string (searches from right to left), or -1 if the string is not found.

substring(start-index [, end-index])

  • Returns a substring, up to but not including end-index; the indexes do not have to be in numerical order.

substr(start-index [, length])

 

split(separator [, limit])

  • Returns an array of substrings

match(regex)

  • Returns an array of matching values.

replace(search-str, new-str)
replace(regex, new-str)

  • Returns the resulting string value. The original object is not modified.

Escape characters

\b    Backspace
\f    Form feed
\n    New line
\r    Carriage return
\t    Tab
\'    Apostrophe or single quote
\"    Double quote
\     Backslash

 

Resources URL: 
notes/javascript/resources
Sources URL: 
notes/javascript/sources

See Also