How to get the ASCII value in JavaScript for the characters [duplicate]

Here is the example:

var charCode = "a".charCodeAt(0);
console.log(charCode);

Expand snippet

Or if you have longer strings:

var string = "Some string";

for (var i = 0; i < string.length; i++) {
  console.log(string.charCodeAt(i));
}

Expand snippet

String.charCodeAt(x) method will return ASCII character code at a given position.

Leave a Comment