Typed arr ( type[] )
An array containing elements of a specific type.
Syntax
let name: type[] = [...];
Description
number[] is an array that can only contain numbers, string[] only text.
Example
Loading editor…
Expected output
[ 95, 90, 105 ]
When to use?
Type-safe lists (scores, names).
Common mistakes
- ⚠️ const a: number[] = [1, "two"]; → ERROR: text cannot be in the array.