Skip to content
Afa' Afa'

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.

https://gist.github.com/lovasoa/11357947

Something wrong or want to discuss this article? Get in touch

Search articles and projects

Type to filter articles and projects. Use the arrow keys to move through results and Enter to open one. Press Escape to close.