Search code examples
javascriptnumericalphabet

how do i get the numeric representation of a character in javascript?


I'd like to get a javascript numeric representation for a letter to do some relative manipulation i.e. in pseudocode to conduct an operation like 'a'.getNumberRep - 'b'.getNumberRep.

Best way to do this in js?


Solution

  • 'a'.charCodeAt(0) - 'b'.charCodeAt(0)