charAt Method (String)

charAt Method (String) (JavaScript)


Returns the character at the specified index.

strObj. charAt(index)


Required. Any String object or string literal.


Required. The zero-based index of the desired character.

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 that are out of range return an empty string.

The following example illustrates the use of the charAt method:

document.write(str.charAt(str.length - 1));

// Output: Z


Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported in Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

Applies To: String Object (JavaScript)

© 2015 Microsoft