Printing all ASCII characters in Javascript

19,360

I'm not sure how exactly you want to print, but this will console.log printable ascii

for(var i=32;i<127;++i) console.log(String.fromCharCode(i));

You can document.write then if that's your intention. And if the environment is unicode, it should work for unicode as well, I believe.

Share:
19,360

Related videos on Youtube

Amit Tomar
Author by

Amit Tomar

Generalist, with 8+ years of experience in : 3D Computer Graphics (OpenGL, WebGL, Three.JS, Blender). Also have exposure to UI (Qt-QML, Javascript), middleware (C/C++) &amp; backend (Python-Flask)

Updated on June 25, 2022

Comments

  • Amit Tomar
    Amit Tomar almost 2 years

    I need to do something like this:

    1. Have a variable of some type.
    2. Run in a loop and assign all the possible ASCII characters to this variable and print them, one by one.

    Is something similar possible for UNICODE also?

  • Jukka K. Korpela
    Jukka K. Korpela over 11 years
    No font contains all Unicode characters (even font technology currently prevents that). On the other hand, rendering engines may use different fonts – e.g., web browsers generally use some fallback fonts.
  • Yaroslav Bigus
    Yaroslav Bigus about 11 years
    what about extended ascii?
  • Michael Krelin - hacker
    Michael Krelin - hacker almost 9 years
    It basically works with whatever encoding the interpreter uses. You may need to change range in the for loop, though ;-)
  • Dmytro
    Dmytro almost 7 years
    Array.from(Array(127).keys()).slice(32).map(a => String.fromCharCode(a)) in one expression to get the array of them all. With zeroTo function it gets shorter, zeroTo(127).slice(32).map(a => String.fromCharCode(a))