I want to make an array containing all the letters and numbers on the keyboard ( !, @, #, $, %, &, etc.) via code, without declaring it. Is there any way to do this in js?
CodePudding user response:
This will give characters that are displayable on the screen.
let characters = [];
for (let i=32; i<127; i )
characters.push( String.fromCharCode(i) );
CodePudding user response:
I like 1 liners so
const characters = [...Array(95).keys()].map(i => String.fromCharCode(i 32))
CodePudding user response:
There are 95 characters so you can make an array of 95 elements and map the items to the String char code that matches the index 32
.
const characters = Array.from(Array(95), (val,i) => String.fromCharCode(i 32))