in my application (React-typescript) I have some documents in the type of
interface IDocument {id: string; questions: IQuestion[];}
interface IQuestion {number: string; answer: string; }
so an array of documents will look like i.e:
doscuments: IDocument[] = [
{id: "a",
questions: [
{ number: "1", answer: "answer1" },
... /* more number answer*/
]},
{id: "b",
questions: [
{ number: "1", answer: "answer1" },
... /* more number answer*/
]}
];
now I want to convert it to an alternative form of type
interface IAlternative {
[key: string]: string;
}
to have key-value pairs of i.e.
alterDocs: IAlternative = {a1:"answer1", a2:"answer2",...,b1:"answer1",...}
For that I have the code below but cannot construct a pair with doc.id+question.number
as key and question.answer
as the value
documents.forEach(doc:IDocument=>{
doc.questions.forEach(question=>{
const pair= {} // I cannot construct this pair
alterDocs={...alterDocs,...pair}
})
})