If you are already using a for-loop instead of string.replace to iterate over the string, you can also use str.charCodeAt(i), so you don't have to convert the string to array first.
Then, you can use const inside the for loop instead of let outside. If you don't plan to replace the array, you can and should directly assign it (though it's not necessary).
Other than that, check my comment to Chris' post. ASCII characters are organized in a useful manner, something you can use.
If you are already using a for-loop instead of
string.replace
to iterate over the string, you can also usestr.charCodeAt(i)
, so you don't have to convert the string to array first.Then, you can use
const
inside the for loop instead oflet
outside. If you don't plan to replace the array, you can and should directly assign it (though it's not necessary).Other than that, check my comment to Chris' post. ASCII characters are organized in a useful manner, something you can use.
Thanks Alex . I will try that