Version: v0.7.0 - Beta.  We welcome contributors & feedback.

String.getCharCode

getCharCode($index = 1) -> string

Description

Get the ASCII value of the character at $index.

If $index is negative, it counts from the end of the string.

If the index is outside the bounds of the string, it will return -1. (Note: It would be simpler if it returned 0, but that is the ASCII code for NULL).

This is the opposite of String.charFromCode.

'a'.getCharCode()
//= 97

'abcdef'.getCharCode(3)
//= 99 (code for 'c')

'abcdef'.getCharCode(-1)
//= 102 (code for 'f')

'abcdef'.getCharCode(100)
//= -1

See Also