string方法中字符与Unicode编码的相互转化:fromCharCode(),charCodeAt()

String.fromCharCode(num1,num2,...numX)

将Unicode编码转字符串

console.log(String.fromCharCode(65))  //A

//根据Unicode输出A-D

for(let i=65;i<=90; i++){
  let k = String.fromCharCode(i)
  console.log(k)
}

str.charCodeAt(index)

返回指定位置的字符对应的Unicode编码

let str = 'AB'

console.log(str.charCodeAt(0))   //65
posted @ 2019-06-28 14:33  叶子玉  阅读(2609)  评论(0编辑  收藏  举报