Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

charAt Method (JavaScript)

Returns the character at the specified index.

strObj.charAt(index)

strObj

Required. Any String object or literal.

index

Required. Zero-based index of the desired character. Valid values are between 0 and the length of the string minus 1.

The charAt method returns a character value equal to the character at the specified index. The first character in a string is at index 0, the second is at index 1, and so forth. Values of index out of valid range return an empty string.

The following example illustrates the use of the charAt method:

function charAtTest(n)
{
   var str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
   var s = str.charAt(n - 1);
   return(s);
}

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.

Applies To: String Object (JavaScript)

Show:
© 2015 Microsoft