TypeScript String Length - Example - Tutorial Kart

TypeScript String Length ? Example

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.

example.ts

var str = new String("Hello World") var len = str.length console.log(str) console.log("The length of above string is : "+len)

When you convert the code into JavaScript using the command tsc example.ts , you will get the following JavaScript Code.

example.js

var str = new String("Hello World"); var len = str.length; console.log(str); console.log("The length of above string is : " + len);

If you run this JavaScript code in a web-browser, the output in the console would be as shown in the following screenshot:

You can also use the length property directly on a string constant. example.ts var len = "Hello World".length console.log("The length of above string is : "+len)

The output would be same as in the above example.

TypeScript

TypeScript Tutorial TypeScript Variables TypeScript if TypeScript if-else TypeScript Switch TypeScript For Loop TypeScript While Loop TypeScript Do-While Loop TypeScript Arrays TypeScript Tuples TypeScript Unions TypeScript Functions TypeScript Anonymous Functions

TypeScript Object Oriented Concepts

TypeScript Class TypeScript Inheritance TypeScript Method Overriding TypeScript Interface

TypeScript String Operations

TypeScript String Length TypeScript String Split

................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download