0

I want to declare a global array in Typescript so that I can access it with "this" from anywhere. In javascript I would declare it like "var anArray=[]". How do I do exactly the same with Typescript.

anArray:Array<any> seems not working.

2
  • 2
    It's not about how you declare it, it's about where you declare it. window.anArray: any[] = []; should work fine from anywhere, but obviously global variables are not the way to go, in any language. Commented Jul 31, 2017 at 5:58
  • 1
    Are you seeing any errors from the compiler? Have you tried: var anArray: Array<any> = []; Commented Jul 31, 2017 at 5:59

1 Answer 1

1

Try this format

let list: any[] = [5, true, "one"];

Refer : Documentation Link

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.