To initialize an array in TypeScript, you can use type annotations or inference.
In this example,
numbers
with type annotation and initialize it with integer values.let numbers: number[] = [1, 2, 3, 4, 5];
console.log(numbers);
[ 1, 2, 3, 4, 5 ]
In this example,
fruits
with string values without type annotation.let fruits = ['Apple', 'Banana', 'Orange'];
console.log(fruits);
[ 'Apple', 'Banana', 'Orange' ]
In this tutorial, we learned How to Initialize an Array in TypeScript language with well detailed examples.