charCodeAt() 메서드는 주어진 인덱스에 있는 문자의 유니코드 값을 나타내는 숫자를 반환합니다. 유니코드 코드 포인트의 범위는 0에서 1,114,111입니다. 처음 128개의 유니코드 코드 포인트는 ASCII 문자 인코딩과 직접 일치합니다.
다음 매개변수는 charCodeAt(index)에서 지원됩니다 -
- 색인 - 문자열 길이보다 작은 0과 1 사이의 정수. 지정하지 않으면 기본값은 0입니다.
예시
다음 코드를 실행하여 문자의 유니코드 값을 나타내는 숫자를 반환할 수 있습니다. -
<html>
<head>
<title>JavaScript String charCodeAt() Method</title>
</head>
<body>
<script>
var str = new String( "This is string" );
document.write("str.charCodeAt(0) is:" + str.charCodeAt(0));
document.write("<br />str.charCodeAt(1) is:" + str.charCodeAt(1));
document.write("<br />str.charCodeAt(2) is:" + str.charCodeAt(2));
document.write("<br />str.charCodeAt(3) is:" + str.charCodeAt(3));
document.write("<br />str.charCodeAt(4) is:" + str.charCodeAt(4));
document.write("<br />str.charCodeAt(5) is:" + str.charCodeAt(5));
</script>
</body>
</html>