capypad
0 day streak
typescript / beginner
Snippet

Defining Arrays

TypeScript allows you to define arrays that contain only a specific type of element, preventing accidental mixed-type arrays.

snippet.ts
typescript
1
2
const fruits: string[] = ["Apple", "Banana"];
const scores: Array<number> = [95, 88, 100];
Breakdown
1
string[]
The most common way to define an array of strings.
2
Array<number>
A generic way to define an array of numbers.