1

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt

I need to calculate byte size by given string which given from <input />.

I've found javascript function charCodeAt() which seems to be good to use.

It says charCodeAt uses utf-16, but I use <meta charset="utf-8"/>

Is it okay to use charCodeAt() in utf-8?

JillAndMe
  • 3,989
  • 4
  • 30
  • 57
  • 1
    Although an HTML document might be encoded with UTF-8, HTML, semantically, doesn't have anything to do with any character encoding, only the Unicode character set. Any, you are right, JavaScript uses the UTF-16 character encoding. So, what is your question about byte count and UTF-8? Please show your code it applicable. – Tom Blodget Oct 04 '19 at 21:31

1 Answers1

0

I know you asked about charCodeAt() but FYI looks like you can use:

new Blob(['string']).size

Or if using Node:

Buffer.byteLength('string', 'utf8')

https://stackoverflow.com/a/52254083/5670890

Kevin
  • 141
  • 7