JavaScript(JS) JS find ascii value of character

h‮sptt‬://www.theitroad.com

In JavaScript, you can use the charCodeAt() method to find the ASCII value of a character. The charCodeAt() method returns an integer between 0 and 65535 that represents the UTF-16 code unit at the specified index of a string. If you pass in an index of 0, you will get the ASCII value of the first character.

Here's an example:

let char = 'A';
let asciiValue = char.charCodeAt(0);
console.log(asciiValue); // Output: 65

In the example above, we define a variable char and assign it the value 'A', which is a single character string. We then use the charCodeAt() method to get the ASCII value of the first character in the string by passing in an index of 0. The method returns the integer value 65, which is the ASCII value of the character 'A'.

Note that the charCodeAt() method only works for single characters. If you want to find the ASCII values of all the characters in a string, you can use a loop to iterate over the string and call the charCodeAt() method for each character.