如何獲得值爲「類別2中的第二個問題?」的問題的答案?根據關鍵值和變化的大小從陣列中獲取價值
我需要用JavaScript來做到這一點。類別名稱將是隨機的,儘管我知道這個值以及我正在尋找答案的問題的值。
類別和問題的數量會有所不同,因此解決方案不得將固定大小依賴於此數組。
不會有任何重複的類別或問題。
任何幫助將是真棒我一直在努力與此。什麼讓我是類別名稱正在改變,我不知道如何匹配一個值。
JS
{
"Category 1":[
{
"question":"Fist question in category 1?",
"answers":[
"first answer",
"second answer",
"third answer",
"fourth answer"
]
},
{
"question":"Second question in category 1?",
"answers":[
"first answer",
"second answer",
"third answer",
"fourth answer"
]
}
],
"Category 2":[
{
"question":"First question in category 2?",
"answers":[
"first answer",
"second answer",
"third answer",
"fourth answer"
]
},
{
"question":"Second question in category 2?",
"answers":[
"first answer",
"second answer",
"third answer",
"fourth answer"
]
},
{
"question":"Third question in category 2?",
"answers":[
"first answer",
"second answer",
"third answer",
"fourth answer"
]
}
]
};
你沒事使用圖書館辦呢? – Khang
只是一些簡單的循環應該做的伎倆......我不明白圖書館將如何幫助 – qxz
@khang - 爲什麼他需要一個圖書館,當他需要的功能是建立在本地和相對容易實現? for循環功能強大。 – Derek