typescript / beginner
Snippet
Basic Array Annotations
Arrays in TypeScript can be restricted to hold only a specific type of element, ensuring that the collection remains consistent.
snippet.ts
1
2
let fruits: string[] = ["Apple", "Banana"];let scores: Array<number> = [85, 92, 78];
Breakdown
1
let fruits: string[] = ["Apple", "Banana"];
Uses the square bracket syntax to define an array of strings.
2
let scores: Array<number> = [85, 92, 78];
Uses the generic Array syntax to define an array of numbers.