I have nested object and from that render object i want to access data according to user click. Example : in below object i loaded first question with response.pathway.question and answer with response.pathway.answers now if user click on yes then i next next key should be response.pathway.answers.Yes and if user clicks on No then next key should be response.pathway.answers.No in short what ever answer user select it should be added at last.
Now problem is i am using flatlist to show answers which return item and when i add that item at last of object key its giving error . And i know its giving error because there is no key in object like response.pathway.answers.item .So my question is how can i make this item dynamic like if user select yes then it should be like response.pathway.answers.Yes and vice versa. (Note inside answers key could be anything not only yes no).
{
"pathway": {
"question ": "this is first question",
"answers": {
"Yes": {
"question": "this question i want to access if user click on yes"
},
"No": {
"question": "this question i want to access if user click on no"
}
}
}
}
response["pathway"]["answer"]["Yes"],you can store key name in variable and get the desired result.