当它应该生成string?
let str = "hello";
let string = []
for(let s in str){
string.push(str.codePointAt(s))
}
console.log(string) // ASCII
let back = []
for(let s in string){
back.push(String.fromCharCode(s))
}
console.log(back) // unicode??
for (let s in string)
迭代每个元素的索引。你在转换数字0
,1
,2
,…
如果在循环中添加一个简单的console.log(s)
,或者检查输出,其中每个元素显然是从0开始的顺序:
['x00', 'x01', 'x02', 'x03', 'x04', 'x05', 'x06', 'x07', 'b']