String.fromCharCode() 메서드는 UTF-16 코드 유닛의 시퀀스로부터 문자열을 생성해 반환합니다.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
구문
String.fromCharCode(num1[, ...[, numN]])
매개변수
num1, ..., numN- UTF-16 코드 유닛인 숫자 뭉치. 가능한 값의 범위는 0부터 65535(0xFFFF)까지입니다. 0xFFFF를 초과하는 값은 잘립니다. 유효성 검사는 하지 않습니다.
반환 값
주어진 UTF-16 코드 유닛 N개로 이루어진 문자열.
설명
이 메서드는 String 객체가 아닌 문자열을 반환합니다.
fromCharCode()는 String의 정적 메서드이기 때문에 String.fromCharCode()로 사용해야 합니다.
예제
fromCharCode() 사용하기
다음 예제는 문자열 "ABC"를 반환합니다..
String.fromCharCode(65, 66, 67); // "ABC" String.fromCharCode(0x2014) // "—" String.fromCharCode(0x12014) // 숫자 '1'은 무시해서 "—"
더 큰 값과 사용하기
초기 JavaScript 표준화 과정에서 예상했던 것처럼, 대부분의 흔한 유니코드 값을 16비트 숫자로 표현할 수 있고, fromCharCode()가 많은 흔한 값에서 하나의 문자를 반환할 수 있지만, 모든 유효한 유니코드 값(최대 21비트)을 처리하려면 fromCharCode()만으로는 부족합니다. 높은 코드 포인트의 문자는 써로게이트surrogate 값 두 개를 합쳐 하나의 문자를 표현하므로,String.fromCodePoint()(ES2015 표준) 메서드는 그러한 쌍을 높은 값의 문자로 변환할 수 있습니다.
명세
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.2. |
| ECMAScript 5.1 (ECMA-262) The definition of 'StringfromCharCode' in that specification. |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'String.fromCharCode' in that specification. |
Standard | |
| ECMAScript Latest Draft (ECMA-262) The definition of 'String.fromCharCode' in that specification. |
Draft |
브라우저 호환성
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
fromCharCode | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 4 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support