gpt4 book ai didi

javascript - codePointAt 和 charCodeAt 的区别

转载 作者:行者123 更新时间:2023-12-03 12:04:58 26 4
gpt4 key购买 nike

String.prototype.codePointAt() 和有什么区别和 String.prototype.charCodeAt()在 JavaScript 中?

'A'.codePointAt(); // 65
'A'.charCodeAt(); // 65

最佳答案

来自 charCodeAt 上的 MDN 页面:

The charCodeAt() method returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index.

The UTF-16 code unit matches the Unicode code point for code points which can be represented in a single UTF-16 code unit. If the Unicode code point cannot be represented in a single UTF-16 code unit (because its value is greater than 0xFFFF) then the code unit returned will be the first part of a surrogate pair for the code point. If you want the entire code point value, use codePointAt().


TLDR;
  • charCodeAt() UTF-16
  • codePointAt() 统一码 .
  • 关于javascript - codePointAt 和 charCodeAt 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36527642/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com