TypeScript Arrays


Arrays are an important data type in JavaScript. Now, let's see how to specify the data type for an array in TypeScript.

An array is a user-defined data type. An array is a homogeneous collection of similar types of elements that have a contiguous memory location and which can store multiple values of different data types.

An array is a type of data structure that stores the elements of a similar data type and considers it as an object too. We can store only a fixed set of elements and can’t expand its size, once its size is declared.

The array follows index-based storage i.e. the first element of an array is stored at index 0 or index ‘i’ and the remaining elements are stored at the location ‘i+1’.

Typescript supports an array just like that in JavaScript. There are two ways to declare an array in typescript:

  • Using square brackets. 
  • Using a generic array type. 

Using square brackets.

Using a generic array type.