Exercise 11 - Names: Store your friends names in a array. Print each in the list, one at a time.

Опубликовано: 22 Март 2026
на канале: TypeScript Insights
966
15

In TypeScript, you can declare and initialize an array using the following syntax:

```typescript
let arrayName: Type[] = [element1, element2, element3, ...];
```

Here's an example of declaring and initializing an array of numbers:

```typescript
let numbers: number[] = [1, 2, 3, 4, 5];
```

In the above example, `numbers` is the name of the array, and it is declared as an array of numbers (`number[]`). The array is then initialized with the elements 1, 2, 3, 4, and 5.

You can also declare and initialize an array of strings:

```typescript
let names: string[] = ["Alice", "Bob", "Charlie"];
```

In this example, `names` is declared as an array of strings (`string[]`), and it is initialized with the strings "Alice", "Bob", and "Charlie".

You can replace the `Type` with the appropriate data type (such as `number`, `string`, `boolean`, etc.) based on the type of elements you want to store in the array.

You can also declare an empty array without any initial elements:

```typescript
let emptyArray: Type[] = [];
```

This declares an empty array of the specified type, which you can later populate with elements.

Remember to replace `Type` with the desired data type when declaring an array in TypeScript.