0

I have following structure 1 questionnaire got many questionSection 1 questionSection got many questions

i want to get all the questions. I tried following

const allQuestions: Question[] = [];
questionSections.forEach(section => {
  section.questions.forEach(question => {  
    allQuestions.push(question)
  });
});

Is there a better way to achieve the same result?

Thanks

Mukil Deepthi
  • 6,072
  • 13
  • 71
  • 156
  • Since there are no browser constraints specified, you could use: `const allQuestions = questionSections.flatMap(s => s.questions)`. - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/flatMap – Caramiriel Sep 23 '22 at 14:41

0 Answers0