To get the length of an array in TypeScript, you can use the length
property of the array.
In this example,
numbers
with some values.length
property of the array object numbers
, and store the returned value in length
variable.Array.length
property returns the length of this array.length
to standard output.let numbers: number[] = [1, 2, 3, 4, 5];
let length: number = numbers.length;
console.log(`Length of array is: ${length}`);
Length of array is: 5
In this example,
colors
with some values.length
property of the array object colors
, and store the returned value in length
variable.Array.length
property returns the length of this array.length
to standard output.let colors: string[] = ['red', 'green', 'blue'];
let length: number = colors.length;
console.log(`Length of array is: ${length}`);
Length of array is: 3
In this tutorial, we learned How to Get Array Length in TypeScript language with well detailed examples.