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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM