In TypeScript, array declaration is similar to JavaScript but with added type annotations.
In this example,
numbers
with type annotation number[]
and initialize it with some values.let numbers: number[] = [1, 2, 3, 4, 5];
console.log('Array elements:', numbers);
Array elements: [ 1, 2, 3, 4, 5 ]
In this example,
names
with type annotation string[]
and initialize it with some values.let names: string[] = ['Alice', 'Bob', 'Charlie'];
console.log('Array elements:', names);
Array elements: [ 'Alice', 'Bob', 'Charlie' ]
In this tutorial, we learned How to Declare an Array in TypeScript language with well detailed examples.