February 27, 2000 - Accessing String's Characters

Yehuda Shiran February 27, 2000
Accessing String's Characters
Tips: February 2000

Yehuda Shiran, Ph.D.
Doc JavaScript

In most programming languages, you can access individual characters of a string by the array notation. For example, if the string variable is foobar, then the third character of this string would have been foobar[2]. In JavaScript, this is not that trivial. You need to use the charAt() method. It takes a single parameter: the index of the character in the string. Back to our above example, the third character of foobar could be derived as follows:

foobar.charAt(2)