Converting ASCII strings to array in JavaScript

This certainly is possible, it will require an extra step to convert your ASCII string into integers.

This example uses ES6 spread syntax to convert the string into an array of characters. The map and charCodeAt functions are then used to convert the characters into an array of integers.

var s = 'hello world'
[...s].map(ch => ch.charCodeAt())

[104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100]

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.