weiqinl

十进制ASCII码转换成字符

  1. 使用String.fromCodePoint(num1[, ...[, numN]])方法
String.fromCharCode(65) // A
String.fromCharCode(90) // Z
String.fromCharCode(97) // a
String.fromCharCode(122) // z
  1. 也可以使用String.fromCharCode(num1[, ...[, numN]])方法
String.fromCodePoint(65) // A
String.fromCodePoint(90) // Z
String.fromCodePoint(97) // a
String.fromCodePoint(122) // z

fromCodePoint(), fromCharCode()两个都是String的静态方法,所以直接使用,不需要实例化。
两者的主要区别是:
fromCharCode() 出现的早,可以处理常用的字符编码
fromCodePoint() ES2015出现的,可以处理高位编码。

字符转换成十进制ASCII码

\'A\'.charCodeAt() // 65
\'a\'.charCodeAt() // 97
\'Z\'.charCodeAt() // 90
\'z\'.charCodeAt() // 122

参考:

  1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
  2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint
  3. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
猜你喜欢
  • 2022-12-23
  • 2022-02-03
  • 2022-12-23
  • 2021-07-04
  • 2021-10-06
  • 2022-12-23
相关资源
相似解决方案