String that contains all ascii characters

前端 未结 7 1294
灰色年华
灰色年华 2021-02-03 23:01

I want to create a string in JavaScript that contains all ascii characters. How can I do this?

7条回答
  •  闹比i
    闹比i (楼主)
    2021-02-03 23:45

    Just loop the character codes and convert each to a character:

    var s = '';
    for (var i=32; i<=127;i++) s += String.fromCharCode(i);
    

提交回复
热议问题