Compute the length in bytes of a javascript string, when encoded in UTF8
Compute the UTF-8 byte length of a JavaScript string, which String.length does not give you.
1 min read
Updated
JavaScript's String.length counts UTF-16 code units, not bytes. This note points to a small utility that computes the UTF-8 byte length of a string, which matters when sizing payloads or storage. The reference is below.