
上QQ阅读APP看书,第一时间看更新
Array
The array data type is meant to hold a collection of values of specific types. In TypeScript, we can define arrays in two ways, which are as follows:
var even:number[] = [2, 4, 6, 8, 10];
This statement declares an array variable of the number type using square brackets ([]) after the data type number, and it is assigned with a series of even numbers from 2 to 10. The second way to define array is as follows:
var even:Array<number> = [2, 4, 6, 8, 10];
This statement uses the generic array type, which uses the Array keyword followed by angle brackets (<>) that wrap the number data type.