For me the syntax was a little more than the accepted answer because I was using a full array type.
stringArr: Array<string> = [];
Also, this would work too
stringArr: string[] = [];
Just 2 ways to type a new array
1
votes
class A implements OnInit {
stringArr: string=[];
ngOnInit() {
for(let i=0; i<4; i++) {
this.stringArr.push("aaa");
}
}
}
Here stringArr is defined as string, but not as an array of string. Define stringArr as blank array [].
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more