How to count the number of symbols in a string?

Mathias Bynens mathias at qiwi.be
Fri Nov 30 12:54:32 PST 2012


Thanks for the useful info, Andrea and Yusuke!

A `{code}points` property/getter on the `String.prototype` like Andrea suggested earlier sure sounds good to me.

IMHO a solution to the “string length” problem should definitely be added to ES6, as even major sites like Twitter.com are doing it wrong currently. Here’s a screenshot of the tweet textarea containing only a single astral symbol: http://i.imgur.com/IlFxj.png Note how the counter below says “138 [characters left]” instead of 139, as it should.


More information about the es-discuss mailing list