How to print all printable ascii values in JavaScript and how to print the ascii value of anything

How to print all printable ascii values in JavaScript and how to print the ascii value of any character

spew ("hi");

var all = "";

for (var i = 32; i < 127; i++) {
  var char = String.fromCharCode(i);
  all += char;
  spew (i + " " +  char);
}
spew("-----------");
spew("My sample string is:");
spew(all);
spew("------------");
for (i = 0; i < all.length; i++) {
  var ccode = all.charCodeAt(i);
  var cchar = all.substring(i, i+1);
  spew(cchar + " " + ccode);
}
//spew(all);

function spew(s) {
  var hello = document.getElementById("hello");
  var html = hello.innerHTML;
  hello.innerHTML = html + "<br>" + s;
}
Advertisements

About SunKing2

Former web developer, guitar player, started Piano 2012 -yes still doing it! Recovery, sobriety, mental health advocate.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s