简体   繁体   中英

How to convert string of ASCII codes to string of characters?

Need to convert a string of ASCII code into the corresponding string of characters. String.fromCharCode() works only if I directly type in the ASCII codes but I need to use a variable name for this.

code = codeArr.join('.'); // 104,101,108,108,111,32,119,111,114,108,100

String.fromCharCode(104,101,108,108,111,32,119,111,114,108,100); // hello world

String.fromCharCode(code); // this returns blank? No errors just blank

Use Spread syntax .

 let code = [104,101,108,108,111,32,119,111,114,108,100]; console.log(String.fromCharCode(...code)); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM