Open In App

TypeScript | String Length Property

Last Updated : 18 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

The Length Property() in TypeScript which is used to get the length of the string 
Syntax:

string.length 

Return Value: This method returns the length to the String function that created the object. 
Below examples illustrate the String Length Property in TypeScript

Example 1: 

JavaScript




<script>
    // Original strings
    var str = "Geeksforgeeks - Best Platform"
       
    // use of length Property
    var newstr = str.length
    console.log("Return Value of Length property:", newstr);
</script>


Output: 

Return Value of Length property: 
29

Example 2: 

JavaScript




<script>
    // Original strings
    var str = new String("TypeScript - String length Property"); 
   
    // use of length Property
    var newstr = str.length 
    console.log("Length:", newstr);
</script>


Output: 

Length: 
35

Previous Article
Next Article

Similar Reads

TypeScript String Prototype Property
The Prototype Property in TypeScript which is used to add properties and methods to an object. Syntax: string.prototype Return Value: This method does not returns any value. Below examples illustrate the String Prototype property in TypeScriptExample 1: C/C++ Code function Person(name:string, job:string, yearOfBirth:number) { this.name= name; this.
1 min read
TypeScript | String Constructor Property
The Constructor Property() in TypeScript which is used to returns a reference to the String function that created the object. Syntax: string.constructor Return Value: This method returns the reference to the String function that created the object. Below example illustrate the String Constructor Property in TypeScript Example 1: C/C++ Code &lt;scri
1 min read
What is the difference between 'String' and 'string' in TypeScript ?
Unlike JavaScript, TypeScript uses static typing, i.e. it specifies what kind of data the variable will be able to hold. Since TypeScript is a superscript of JavaScript, it also holds a distinction between a string and String. The usage of a string object in JS (or TS for that matter) is very minimal. String objects have the feature of adding a pro
4 min read
TypeScript String String.fromCodePoint() Method
The fromCodePoint() is an inbuilt TypeScript String method. It is mainly used to get the string value of any given Unicode point value. This method is really helpful when you want to handle characters that are not readily available through keyboard input. Syntax:String.fromCodePoint(...codePoints: number[]): stringParameters:...codePoints: An array
1 min read
How to Declare a Fixed Length Array in TypeScript ?
To declare a Fixed-length Array in TypeScript you can use a Tuple. Tuple types allow you to specify the types for each element in the array and, importantly, define a fixed number of elements in a specific order. In this article, we are going to learn how to declare a fixed-length array in TypeScript. Syntaxtype FixedLengthArray = [Type1, Type2, ..
2 min read
How to Split an Array of Strings into Chunks of Equal Length in TypeScript ?
In TypeScript, to split an array of strings into chunks of equal length we need to divide the array into the smaller subarrays, in which each contains the number of elements based on the chunk size. These are the following approaches:Table of Content Using for LoopUsing Array.from() methodUsing reduce() methodUsing for LoopIn this approach, we use
3 min read
Find the Length of a Dictionary in TypeScript
In TypeScript, to find the length of a dictionary, there is no built-in property for objects that determines the length of the dictionary. The length of the input dictionary can be retrieved by counting the pairs of key values in it. There are several approaches available in TypeScript for finding the length of a dictionary which are as follows: Ta
3 min read
Find the Length Tuple in TypeScript ?
In TypeScript, a Tuple is the data structure that allows storing a fixed number of elements of different types in a specific order. We can find the length of a tuple using various approaches that are implemented in this article in terms of examples. There are several approaches available in TypeScript for finding the length of a tuple which are as
3 min read
How to use property decorators in TypeScript ?
Decorators are a way of wrapping an existing piece of code with desired values and functionality to create a new modified version of it. Currently, it is supported only for a class and its components as mentioned below: Class itselfClass MethodClass PropertyObject Accessor ( Getter And Setter ) Of ClassParameter Of Class Method Note: Currently, dec
4 min read
TypeScript Object Type Excess Property Checks
In this article, we are going to learn about Object Type Index Signatures in Typescript. TypeScript is a popular programming language used for building scalable and robust applications. In TypeScript, excess property checks refer to the behavior where TypeScript checks for extra or unexpected properties when you try to assign an object to a type wi
3 min read