​why does this code give me an array of undefined when i do console.log(this.itemToSend); ?

 
element: Element = {
linkId: '',
text: '',
elem: [{
valueString: '',
}]
};



itemToSend: {
resourceType: string;
extension: [
{
url: string;
valueCode: string;
},
{
url: string;
valueDateTime: string;
}
],
status: string;
subject: {
reference: string;
display: string;
},
authored: string;
elements: any [];
};

items: Item [];

item: Item = {
linkId: '',
text: '',
answer: ''
};

onSend() {
this.itemToSend = {
resourceType: 'QuestionnaireResponse',
extension: [
{
url: '',
valueCode: 'Demetre Vasia'
},
{
url: '',
valueDateTime: '2018-09-12T04:00:00.000Z'
}
],
status: 'completed',
subject: {
reference: '',
display: 'Demetre Vasia'
},
authored: '2018-11-08T15:41:00.581+00:00',
elements: []
};

this.itemToSend.elements = this.items.map(el => {
this.element.elem[0].valueString = el.answer;
console.log(this.element.elem[0].valueString);

});
why does it give me an array of undefined when i do console.log(this.itemToSend); ?
You already invited:

Nora

Upvotes from:

the purpose of Array.map is to create an array from a source array, by applying the given function argument (lets call it transformFn) to every element in the source array. When transformFn has only one instruction, the transpile step will add the return implicitly to it. If transformFn is a block function (code between {}), then you need to explicitely add a return instruction in transformFn

If you wanna answer this question please Login or Register