Hi I am new to Typescript and I need to use static array in my code. But when I declared array as follows
private static arrayname:String[];
When I typed this. it didn't show me the array name so I can't able to push any values into this array. Can any one help me in this?
You should use class name instead of "this":
class A {
private static arrayname: string[] = ["a", "b", "c"];
someFunc(): number {
return A.arrayname.length; // Here I'm calling private statis property
}
}
var instanceA = new A();
alert(instanceA.someFunc());
This code works for me in the Typescript playground.
You can use private member inside class functions only. It isn't accessible and visible outside the class declared in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With