myString.charAt( pos ) in ECMAScript 262
Return the character at a particular index in the string.
Arguments
name | type | description |
---|---|---|
pos | Number | The index of the character to< |
- Return Type
- String
Description
As ECMAScript does not differentiate between String types and 'character' types, the return value is actually a single-character String object. If pos
is less than zero or greater than or equal to the length of the string, the result is an empty string.
var msg = 'Hello World!';
var firstChar = msg.charAt(0);
var thirdChar = msg.charAt(2);
var emptyString = msg.charAt(9999);
This method is equivalent to mystring.substring(pos,pos+1)
.