#how to convert array of strings into binary code
1 messages · Page 1 of 1 (latest)
You want each character of each string in the array of strings to be it's ASCII representation in binary?
yeah basically
so i have a list of string in an array and want to create a function that transforms all strings in that array
into an array of binary
Which part are you struggling with specifically?
Seems like a decent starting point.
i get that, the probelem is how do i do it for each string element in an array
// console.log(words);
let binary = []
const generator = function (arr) {
arr.forEach(el => {
console.log(el.charCodeAt(0).toString(2)) + " ";
});
}
generator(words)
seems like im only getting the first letter of a string
That's what charCodeAt(0) does. If you want the second letter you need to use charCodeAt(1). The number in the parenthesis is the index of the letter you want the character code for.