I have been working on this code and trying to figure it out through trial and error:
let _fk = this.selectedIaReportDiscussedTopic$
.map((discussionTopic) => {return discussionTopic.fk_surveyanswer})
.forEach((fk) => {
let surveyAnswerMatches = this.surveyAnswers.filter((sa) => {
return fk === sa._id
})
console.log('surveyAnswerMatches', surveyAnswerMatches)
return surveyAnswerMatches
})
console.log('this is fk', _fk)
I am trying to access the `surveyAnswerMatches` array from outside of the function. However, even though I thought returning the array would allow me to access it through the `_fk` variable, the return value does not get assigned to `_fk`.
How can I access the `surveyAnswerMatches` from outside all the `.forEach` and `.map` calls?
Thank you to the SO community for your help!
Edit: Additional Information
console.log('this.selectedIaReportDiscussedTopic$', this.selectedIaReportDiscussedTopic$)
let surveyAnswerMatches = this.selectedIaReportDiscussedTopic$
.map((discussionTopic) => {return discussionTopic.fk_surveyanswer})
.map((fk) => {
return this.surveyAnswers.filter((sa) => {
return fk === sa._id
})
});
console.log('this is surveyAnswerMatches', surveyAnswerMatches)
console.log('this.surveyAnswers', this.surveyAnswers)