Declare an array in TypeScript

后端 未结 5 2051
不思量自难忘°
不思量自难忘° 2020-12-12 13:31

I\'m having trouble either declaring or using a boolean array in Typescript, not sure which is wrong. I get an undefined error. Am I supposed to use JavaScript

5条回答
  •  难免孤独
    2020-12-12 13:57

    this is how you can create an array of boolean in TS and initialize it with false:

    var array: boolean[] = [false, false, false]
    

    or another approach can be:

    var array2: Array =[false, false, false] 
    

    you can specify the type after the colon which in this case is boolean array

提交回复
热议问题