August 17, 2024
JavaScript String Length
Length is a property of a string object. Through length property you can get the length of a string object that means you can count the number of character, of a particular string object. If you want to count total characters of a string then you will have to write your string object name then a dot (.) then length property. This will return you total number of characters of string object. The example of string length property mentioned below:
Code
<script language='javascript'>
var StringVariable = 'Hello all, this is a string example';
// below mention statement shows you how to count total no.
// Of characters of a string object
var totalCharacter = StringVariable.length;
alert(totalCharacter);
</script>
In above mentioned example we have a string object with the name of StringVariable. Then in other statement we tried to get total number of characters of StringVariable with the help of length property and store it to totalCharacter variable then we alert totalCharacter variable.