Size in TypeScript

Find this useful? Support us: Star on GitHub 6
Category: Array | Language: TypeScript

You can get the size of an array in TypeScript by using the length property. The length property returns the number of elements in the array.

Here is an example:

let numbers: number[] = [1, 2, 3, 4, 5];
console.log(numbers.length); // Output: 5

In the example above, we have an array of 5 numbers. We use the length property to get the size of the array which is 5.

You can also get the size of a string using the length property. Here is an example:

let name: string = "John";
console.log(name.length); // Output: 4

In the example above, we have a string with 4 characters. We use the length property to get the size of the string which is 4.