javascriptjquerystring-length

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


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


Solution

  • You don't need jQuery; you can use the vanilla JavaScript method yourstring.length. See reference here and also here.

    To support Unicode strings, length needs to be computed as following:

    [..."𠮷"].length
    

    or create an auxiliary function

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