Thursday, December 01, 2016

The following is the JavaScript code to display the ASCII character codes for each character of a given string.


function ascii(str) {
    return str
          .split('')
          .map(function (char) {
              return char + ": " + String(char.charCodeAt(0)) + "\n";
          })
          .reduce(function (current, previous) {
              return current + previous;
          });
}
 
alert(ascii("Hello World!"));