How do you get the length of a string?

Solution 1:

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
}

Solution 2:

The easiest way:

$('#selector').val().length

Solution 3:

jQuery is a JavaScript library.

You don't need to use jQuery to get the length of a string because it is a basic JavaScript string object property.

somestring.length;

Solution 4:

HTML

<div class="selector">Text mates</div>

SCRIPT

alert(jQuery('.selector').text().length);

RESULT

10

Solution 5:

You don't need to use jquery.

var myString = 'abc';
var n = myString.length;

n will be 3.