JavaScript Code

JavaScript String charCodeAt()


String charCodeAt()

str.charCodeAt(n)
  • str is a string
  • n is an integer (position/index)

charCodeAt() method returns the UTF-16 code (unicode) character (as integer) from string str present at the index n.

Examples

1. get unicode character at index

let name = 'apple';
let output = name.charCodeAt(3);
console.log(output);

2. n outside the range of string, charCodeAt() returns NaN (Not a Number)

let name = 'apple';
let output = name.charCodeAt(15);
console.log(output);

Copyright @2022