JavaScript Strings

This tutorial describes JavaScript's string methods and demonstrates how to use them. We start by discussing JavaScript string basics. Then we cover:

JavaScript String Methods

The table below lists the JavaScript string methods, gives a brief description of each, and provides links to the pages where they are discussed and demonstrated:

Name Description Page
indexOf Search string; return location of match or -1. Search
lastIndexOf Search string; return location of last match or -1. Search
search Search string using regular expression; return location of match or -1. Search
match Search string using regular expression; return array containing results. Match
replace Return new string resulting from regular expression search and replace. Replace
slice Return substring as specified by start and end locations in string. Slice
substring Similar to slice, but doesn't support negative integer arguments. Slice
substr Return substring as specified by start location and length. Slice
split Return array of substrings by splitting string on separator you specify. Split
toUpperCase Return new string with all characters in uppercase. Basics
toLowerCase Return new string with all characters in lowercase.
charAt Return the character at the specified location. Basics
charCodeAt Return Unicode encoding of character at specified location.
fromCharCode Static method; return string from list of Unicode numeric encodings.
trim Return new string with whitespace removed from beginning and end. (ES5)

Back to top