Skip to content

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.

const lengthInBytes = txt => new Blob([txt]).size;


See also  PHP code snippet - How return cutomize error text the firstOrFail laravel exeption?

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.