How to covert a string of ascii codes to text?

I have a list of ascii character codes returned as '104,101,108,108,111', and I am trying to translate those back to a string:

response = '104,101,108,108,111'
String.fromCharCode(response)

When I pass this to String.fromCharCode(response) then I get ' ' as response, but when I pass input like below I am able to get proper response:

String.fromCharCode(104,101,108,108,111)

How can we pass number codes if we have a string of codes as response?

Upvotes: 0

Views: 141

Answers (1)

trincot
trincot

Reputation: 349873

You need to turn your string into separate arguments: split by comma and spread:

let response = '104,101,108,108,111';
let result = String.fromCharCode(...response.split(","));
console.log(result);

Upvotes: 3

Related Questions