파이썬 알파벳 빈도 수를 구하는 공부를 하다가 js에도 있지 않을까 해서 찾아보고 포스팅한다.
아스키 코드
구문 str.charCodeAt(index)
지정된 인덱스에서 UTF-16 코드 단위를 나타내는 ~ charCodeAt()사이의 정수를 반환한다.
const str = 'abcdefg'
str.charCodeAt(0); // returns 97
str.charCodeAt(2); // returns 99
구문 codePointAt(pos)
지정된 위치의 유니코드 코드 포인트 값인 음이 아닌 정수를 반환한다.
const str = 'abcdefg'
str.codePointAt(0) // 65
str.codePointAt(0).toString(16) // 41
'😍'.codePointAt(0) // 128525
'\ud83d\ude0d'.codePointAt(0) // 128525
'\ud83d\ude0d'.codePointAt(0).toString(16) // 1f60d
'😍'.codePointAt(1) // 56845
'\ud83d\ude0d'.codePointAt(1) // 56845
'\ud83d\ude0d'.codePointAt(1).toString(16) // de0d
'ABC'.codePointAt(42) // undefined