I have this code in my function
let packName: string = respPack.find(a => {a.id == 'name_input'}).answer.replace(/ /,'_');
What I'm trying to do is find the object by matching the id and extract the value of it's answer property. As of right now I'm getting an error telling me
cannot read property answer of undefined.
Am I trying to do this the right way? Here's the rest of my function so you can see what's going on.
saveResponses(){
const respPack = this.ResponseList;
const sendTarget: FirebaseObjectObservable<any> = this.afdb.object('/submissions');
let dataLoad:{ [prop : string]: Array<any> } = {};
let packName: string = respPack.find(a => {a.id == 'name_input'}).answer.replace(/ /,'_');
respPack.forEach( a => {
if(a.answer){
let data = { question: a.question, answer: a.answer, id: a.id };
dataLoad[packName].push(data);
}
else if(a.responses){
let dataChunk = { question: a.question, id: a.id, responses: Array<any> };
a.responses.forEach(resp => {
let respChunk = { response: resp.response, value: resp.value, id: resp.id };
dataChunk.responses.push(respChunk);
});
dataLoad[packName].push(dataChunk);
}
});
sendTarget.set(dataLoad);
}