Get the length of a string in bytes
JavaScript
const bytes = (str) => new Blob([str]).size
TypeScript
const bytes = (str: string): number => new Blob([str]).size
Examples
bytes('hello world') // 11
bytes('🎉') // 4
const bytes = (str) => new Blob([str]).size
const bytes = (str: string): number => new Blob([str]).size
bytes('hello world') // 11
bytes('🎉') // 4