I ran into an issue with counting unicode characters. I need to count total combined unicode characters.
Take this character for example:
द्ध
if you use .length
property on this string it gives you 3. Which is technically correct as it is a combination of
द
, ्
and ध
However, put द्ध
in a text area and then you realize by using arrow keys that it is considered as one character. Only if you use backspace you realize that there are 3 characters.
Edit: Also for your test case please consider that it could be a word. It could be something like,
द्धद्द
This should give 2 with .length
, but gives 6
This is a problem when you want to get or set the current caret position in input elements.