0

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 ?

1
  • Do you mean totalResult: MyInterface[][] = ...? Commented Dec 23, 2019 at 9:38

2 Answers 2

4

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
Sign up to request clarification or add additional context in comments.

1 Comment

but how to initialize in one line with creation of totalresult, to avoid creating result and result2 ?
0

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);

1 Comment

but how to initialize in one line with creation of totalresult, to avoid creating result and result2 ?

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.