Average Joe
Average Joe

Reputation: 4601

Typescript array initialization

here I define the variable results to be an array of strings:

let results: string[]; 

and here below, I assign a value to kick things off:

results['searchCaption'] = "";

and then, the show stops with ERROR TypeError: Cannot set property 'searchCaption' of undefined

What am I missing here? Do I need to define an interface for it first?

Upvotes: 1

Views: 7679

Answers (1)

David Anthony Acosta
David Anthony Acosta

Reputation: 4918

What you want is this:

let results = new Array<string>();
results['searchCaption'] = '';

Upvotes: 9

Related Questions