charAt Method
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

charAt Method 

Returns the character at the specified index of a String object.


function charAt(index : Number) : String

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"; // Initialize variable.
   var s;                                  // Declare variable.
   s = str.charAt(n - 1);                  // Get correct character
                                           // from position n – 1.
   return(s);                              // Return character.
}

Other Resources

Methods

Show:
© 2016 Microsoft