0

count defines the next available q series variables, from the code count is 2 so q8, q9 are available. to extract variables of q series I'm printing as below

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);
    }
bwr
  • 3
  • 1

1 Answers1

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]);
    }
mursalin
  • 1,151
  • 1
  • 7
  • 18
  • While this code may answer the question, providing additional context regarding why and/or how this code answers the question improves its long-term value. – adiga Jul 08 '20 at 05:30