Quantcast
Viewing latest article 2
Browse Latest Browse All 19

Answer by ehmicky for String length in bytes in JavaScript

Based on the following benchmarks, this appears to be the fastest choice that works on all platforms:

I have created the following library that implements the above:

import stringByteLength from 'string-byte-length'stringByteLength('test') // 4stringByteLength('') // 1stringByteLength('\0') // 1stringByteLength('±') // 2stringByteLength('★') // 3stringByteLength('🦄') // 4

Viewing latest article 2
Browse Latest Browse All 19

Trending Articles