count定义下一个可用的q系列变量,因为代码计数为2,所以q8,q9可用。 提取我正在打印的q系列变量,如下所示:
let inputdata = {count:{value:2}, q8:{value:'John'}, q9:{value:'Siva'}};
for (let index = 1; index <= inputdata.count.value; index++) {
let pos = 7+index;
let q = `inputdata.q` + pos;
console.log("Vals: ", q.value);
}
答案 0 :(得分:0)
let inputdata = {count:{value:2}, q8:{value:'John'}, q9:{value:'Siva'}};
for (let index = 1; index <= inputdata.count.value; index++) {
let pos = 7+index;
let q = 'q' + pos;
console.log("Vals: ", inputdata[q]);
}