To get the length of a String in TypeScript, you can use length property of the String object.
When you use the length property on the String object, it returns an integer that represents the length of the string.
String Length in TypeScript
In the following example, we will take a string variable, initialize it with some value and then find its length.
var str = new String("Hello World") var len = str.length console.log(str) console.log("The length of above string is : "+len)
var str = new String("Hello World"); var len = str.length; console.log(str); console.log("The length of above string is : " + len);
You can also use the length property directly on a string constant.
var len = "Hello World".length console.log("The length of above string is : "+len)
The output would be same as in the above example.