To create an array in TypeScript, you can use the array literal syntax or the Array constructor:
index.ts148 chars4 lines
index.ts196 chars4 lines
In the example above, myArray
is an array of numbers, myStringArray
is an array of strings, and myMixedArray
is an array that can hold any type of data (number, string, boolean, etc.).
Note: TypeScript supports type annotations, but if you don't specify the type explicitly, TypeScript will infer the type based on the initial values of the array.
You can access and manipulate array elements using indexes, just like in JavaScript. For example:
index.ts105 chars4 lines
Remember to use the appropriate type annotations to ensure type safety when working with arrays in TypeScript.
gistlibby LogSnag