Arrays

Arrays are available in both JavaScript and TypeScriptData structures in JavaScript are basically represented with objects and arrays. Objects are key-value pairs while arrays have an indexable structure. There is no array type,  rather you provide types for the items that are contained in an array.

You have two options for doing this. You can use the [] symbol pair, as follows:

let textArray: string[];textArray = ["java", "kotlin", "typescript", "the rest..."]

Alternatively, you can use the built-in generic type:

let numberArray: Array<number> = [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

Get TypeScript 2.x for Angular Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.