Quantcast
Channel: String length in bytes in JavaScript - Stack Overflow
Viewing all articles
Browse latest Browse all 19

Answer by ehmicky for String length in bytes in JavaScript

$
0
0

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 all articles
Browse latest Browse all 19

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>