Javascript String codePointAt()

Introduction

Javascript String codePointAt() method returns a Unicode code point value.

str.codePointAt(pos)
  • pos - position of an element in str.

If there is no element at the specified position, undefined is returned.

Using codePointAt()

let a = 'ABC'.codePointAt(1);       
console.log(a);/*w  w  w. ja  v  a 2 s .c o m*/

a = '\uD800\uDC00'.codePointAt(0);
console.log(a);

a = 'XYZ'.codePointAt(42)          // undefined
console.log(a);

Looping with codePointAt()

for (let codePoint of '\ud83d\udc0e\ud83d\udc71\u2764abc') {
   console.log(codePoint.codePointAt(0).toString(16)) 
} 



PreviousNext

Related