Reputation: 5911
I can do this:
result: MyInterface[] = [{prop1: val, prop2: val}]
result2: MyInterface[] = [{prop1: val, prop2: val}]
totalResult = [
this.result,
this.result2
]
this gives me [][]
, the question is how to merge this initialization into creation result
and reusult2
inside totalResult
and telling that totalResult
is array or arrays of MyInterface
?
Upvotes: 0
Views: 79
Reputation: 657
You can do it like this
result: MyInterface[] = [{prop1: val, prop2: val}]
result2: MyInterface[] = [{prop1: val, prop2: val}]
totalResult = [
...this.result,
...this.result2
]
this will add all your item of result and result2 in one array
that's if you want a simple array, if you want an array of array just do it like this
totalResult.push(this.result);
totalResult.push(this.result2);
EDIT after comment :
if you want to avoid result and result 2 do it like this
totalResult : Array<MyInterface[]> = [[{prop1: val, prop2: val}], // result
[{prop1: val, prop2: val}]]; // result2
Upvotes: 4
Reputation: 35
Keep the type for totalResult too, so that you will get clear picture. you can do it like below. [ Array of Arrays of your interfaces ]
result: MyInterface[] = [{prop1: val, prop2: val}]
result2: MyInterface[] = [{prop1: val, prop2: val}]
totalResult: Array<MyInterface[]> = [];
this.totalResult.push(result);
this.totalResult.push(result2);
Upvotes: 0