对于下面的代码,由于“0”,它显然只会在“man”一词中记录“m”。如何记录所有三个字母?
var userChoice = prompt("let me encode something!");
var userChoice = (userChoice.charCodeAt(0) );
console.log (userChoice);
最佳答案
使用普通循环(为了向后兼容旧版本的浏览器)循环遍历 userChoice 中的所有字符
var userChoice = prompt("let me encode something!");
for (var i = 0; i < userChoice.length; i++) {
console.log (userChoice.charCodeAt(i));
}
关于javascript - 如何在 charCodeAt 中记录多个字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39782686/