Get length of a string in bytes using JavaScript
To get the length of a string in bytes, first convert the string to Blob and use the size property of blob object to get its length in bytes.
Advertisements
const lengthInBytes = txt => new Blob([txt]).size; console.log(lengthInBytes("Poopcode")) //8