Every string in JavaScript has a length
property that returns the length of a string.
The syntax for using the length property is shown below:
let stringLength = string.length;
The following example will show you how to use find the length of a string:
let str = "JavaScript String"; let stringLength = str.length; console.log(`The length of a string is ${stringLength}.`); //The length of a string is 17.
If you don't want to use the length property, you can use the for...in
loop to determine the length of a string.
let str = "JavaScript String"; let stringLength = 0; for(let character in str){ stringLength++; } console.log(`The length of a string is ${stringLength}.`); //The length of a string is 17.