标签: javascript node.js express
我正在尝试使用req.body.answerX循环从for获取值,而不是对每个值进行编码。
req.body.answerX
for
我存储了值,例如进入“answer1,answer2”等
answer1
answer2
这是我的尝试:
for( var i = 1; i <= 10; i++){ console.log(req.body.answer[i]); }
这给了我以下错误:
TypeError:无法读取未定义的属性“1”
我怎样才能做到这一点?
答案 0 :(得分:3)
从
console.log(req.body.answer[i]);
到
console.log(req.body["answer" + i]);
供参考,Property Accessor