How do you get the length of a string?

后端 未结 10 1557
星月不相逢
星月不相逢 2020-12-12 12:43

How do you get the length of a string in jQuery?

10条回答
  •  无人及你
    2020-12-12 13:08

    In some cases String.length might return a value which is different from the actual number of characters visible on the screen (e.g. some emojis are encoded by 2 UTF-16 units):

    MDN says: This property returns the number of code units in the string. UTF-16, the string format used by JavaScript, uses a single 16-bit code unit to represent the most common characters, but needs to use two code units for less commonly-used characters, so it's possible for the value returned by length to not match the actual number of characters in the string.

提交回复
热议问题