Languages
[Edit]
EN

JavaScript - convert character to ASCII code

0 points
Created by:
Geospatial-Palus
540

In this article, we would like to show you how to convert characters to ASCII code in JavaScript

Quick solution:

// in case we want to convert a single character 
const charInASCII = 'your char'.charCodeAt(0);

Note: default argument of the charCodeAt() method is 0, so charCodeAt(0) can be replaced with charCodeAt().

Practical example:

In the example below, we convert characters to ASCII code at subsequent positions in the string.

// ONLINE-RUNNER:browser;
const exampleString = 'abc'
console.log(exampleString.charCodeAt(0));  // 97
console.log(exampleString.charCodeAt(1));  // 98
console.log(exampleString.charCodeAt(2));  // 99

References: 

  1. String.prototype.charCodeAt() - MDN Docs

Alternative titles

  1. JavaScript - convert char to ASCII code
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

Cross technology - convert character to ASCII code

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join