0
我有我的路線問題,我想從req.body形式檢查一些數據Express.js req.body parametr陣列
我有途徑
app.post(`/${randomQuestionsArray[0].id}`, (req, res) => {
const reqValue = req.body.answer;
console.log(reqValue);
console.log(randomQuestionsArray[0].reqValue);
}),
片段數據:
const jsonContent = {
"questions": [
{
"id": "1",
'slug': "566fghg6",
"title": "post title 1",
"desc": "This is a test desc 1",
"answer1": {
"answer": "test1",
"value": true
},
"answer2": {
"answer": "test2",
"value": false
},
"answer3": {
"answer": "test3",
"value": false
},
"answer4": {
"answer": "test4",
"value": false
}
},
req.body.answer - 給我表格值等ANSWER1
但我想從陣列
需要一些數據,我創建變量:
const reqValue = req.body.answer; randomQuestionsArray[0].reqValue give me undefined
但如果我寫的手: randomQuestionsArray [0] .answer1給我數據 「答案」:「測試1」, 「值」:真
我怎樣才能把req.body我陣列PARAMS?
使用'randomQuestionsArray [0] [reqValue]'而不是' randomQuestionsArray [0] .reqValue'如果使用硬編碼值適合你。 –
Thx尋求幫助。這是工作 :) –