반응형
charCodeAt
UTF - 16 값을 반환한다.
const str = 'ABCD';
str.charCodeAt(0)//65
str.charCodeAt(1)//66
str.charCodeAt(2)//67
str.charCodeAt(3)//68
str.charCodeAt(4)//NaN
str.charCodeAt(index)
반환값
주어진 인덱스 대한 문자에 대한 UTF-16 코드를 나타내는 숫자
범위 밖으로 넘어갔을 경우 [NaN](https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/NaN)
codePointAt
해당하는 Unicode 값을 반환한다.
const str = 'ABCD';
str.codePointAt(0)//65
str.codePointAt(1)//66
str.codePointAt(2)//67
str.codePointAt(3)//68
str.codePointAt(4)//undefined
const icons = '👍😎👃';
icons.codePointAt(5) //56387
icons.codePointAt(6) //undefined
str.codePointAt(index)
반환값
범위 밖으로 넘어갔을 경우 undefined
String.fromCharCode()
console.log(String.fromCharCode(189, 43, 190, 61));
// expected output: "½+¾="
String.fromCodePoint()
console.log(String.fromCodePoint(9731, 9733, 9842, 0x2F804));
// expected output: "☃★♲你"
반응형
'개발관련 > 자바스크립트 팁' 카테고리의 다른 글
VS CODE TIP (0) | 2021.01.19 |
---|---|
실무에서 값을 할당 할때 많이 사용하는 자바스크립트 연산자 (0) | 2021.01.18 |
GraphQL 맛보기 강의 ep 01 (0) | 2020.09.18 |
자바스크립트 정렬 팁 (0) | 2020.08.21 |
문자열 정렬 팁 (0) | 2020.08.20 |