I've got a React program that asks a user a bunch of different questions, once the user has finished they're taken to basically a results page. Now on that page I want to display results in a meaningful way depending on the answers given. But I am having trouble using the object that contains all the answers.
The survey questions return an object with multiple objects inside, what I'd like to do is iterate over the object and say for example if "what color is the sky" == "blue" correct_answers += 1 or something like that. But it gets a little more complex where some of the nested objects hold an array, while others might hold another object.
The returned answer object looks like this:
Object {
"whats 2 + 2" : "4"
"what color is the sky" : "blue"
"which are breeds of dog" : ["golden retriever", "pug"]
"do you like studying" : Object {row 1: "3", row 2: "5", row 3: "2"}
}
The return type of the object is dependent on what form of question it is, if the user can answer multiple things it returns an array whereas a matrix type of question where they rate certain things on a scale returns another object like "do you like studying".
Is there a way to iterate over answers like this? Or would I have to go about it in a different way. Any help would be greatly appreciated.