JS Property String.length : How do you count special characters?


Hi there!

In JavaScript, how do you count the length of a string if it has special characters?
My native language is spanish. We frecuently use characters like ñ, á, é, í, ó, ú, ü


The String.length property works on any unicode string, and counts all characters in the string without regard of special or not.

 > ['ñ', 'á', 'é', 'í', 'ó', 'ú', 'ü'].length
<- 7
 > ['ñ', 'á', 'é', 'í', 'ó', 'ú', 'ü'].join('').length
<- 7

As we see, both Array.length and String.length work as expected.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.