How do you get the length of a string?

RubbleFord picture RubbleFord · Jun 25, 2009 · Viewed 581.8k times · Source

How do you get the length of a string in jQuery?

Answer

Artem Barger picture Artem Barger · Jun 25, 2009

You don't need jquery, just use yourstring.length. See reference here and also here.

Update:

To support unicode strings, length need to be computed as following:

[..."𠮷"].length

or create an auxiliary function

function uniLen(s) {
    return [...s].length
}