I'm unfortunately still not quite familiar with objects in JS and only programming a bit for my PhD in psychology, so I don't have great programming skills. I've managed to create a nice object which captures my data structure pretty well:
var items = {
anamnese_akut: [{
id: 1,
question: 'Haben Sie die Beschwerden zum ersten Mal?',
answer: 'Ja, also so etwas ist noch nie passiert.'
}, {
id: 2,
question: 'Haben Sie in den letzten Wochen unbeabsichtigt Gewicht verloren?',
answer: 'Nein, bestimmt nicht.'
}],
anamnese_allgemein: [{
id: 3,
question: 'Sind bei Ihnen Vorerkrankungen bekannt?',
answer: 'Eigentlich nicht, nein.'
}, {
id: 4,
question: 'Wurden Sie schon mal operiert?',
answer: 'Ich hatte eine Blinddarmoperation als Kind, und in den letzten zwei Jahren dreimal eine Ausschabung nach Fehlgeburten.'
}]
};
I now want to search for an input variable which contains exactly one of these 4 questions, but can come from both categories. I've already managed to do something like this with an unnested object, using the code from here: JS search in object values, but I cannot get it to work and have no idea how to adapt it to an object with categories like anamnese_akut
and anamnese_allgemein
.
How can I adapt a search for this? After comparing the input with the questions I want to have an index, so that I can give an output of the corresponding answer to the found question.