Years passed and nowadays you can do it natively
(new TextEncoder().encode('foo')).length
Note that it’s not supported by IE (you may use a polyfill for that).
More Related Contents:
- What is the character code for enter? [closed]
- Sending UTF-encoded POST request [duplicate]
- How can I use Unicode-aware regular expressions in JavaScript?
- Concrete JavaScript regular expression for accented characters (diacritics)
- Javascript RegExp + Word boundaries + unicode characters
- How to prevent Unicode characters from rendering as emoji in HTML from JavaScript?
- utf-8 word boundary regex in javascript
- Javascript: Unicode string to hex
- Decode UTF-8 with Javascript
- Remove zero-width space characters from a JavaScript string
- \u200b (Zero width space) characters in my JS code. Where did they come from?
- How can I split a string containing emoji into an array?
- Insert Unicode character into JavaScript
- JavaScript regular expression for Unicode emoji
- Converting punycode with dash character to Unicode
- Javascript unicode string, chinese character but no punctuation
- Javascript string comparison fails when comparing unicode characters
- Printing emojis with JavaScript and HTML
- Why can’t I use accented characters next to a word boundary?
- JavaScript remove ZERO WIDTH SPACE (unicode 8203) from string
- Converting unicode character to string format
- In what JS engines, specifically, are toLowerCase & toUpperCase locale-sensitive?
- Regular Expression for Japanese characters
- javascript and string manipulation w/ utf-16 surrogate pairs
- Unicode string with diacritics split by chars
- Why this regex is not working for german words?
- Writing UTF8 text to file
- How do I fix this missing semicolon syntax error in Javascript?
- Javascript parse error on ‘\u2028’ unicode character
- How to replace non-printable unicode characters (Javascript)