Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
Retrieving certain fields from a json.parse to use as a variable

I'm trying to retrieve all the data from certain objects within a JavaScript array; however I'm having trouble pulling that data. This is the array structure:

{\"responses\":[{\"responseId\":\"R_54lNG4hW4m0ULsi\",\"values\":{\"startDate\":\"2021-08-19T20:36:50.190Z\",\"endDate\":\"2021-08-19T20:36:50.190Z\",\"status\":4,\"finished\":1,\"recordedDate\":\"2021-08-19T20:36:50.190Z\",\"_recordId\":\"R_54lNG4hW4m0ULsi\",\"QID1_TEXT\":\"08/19/2021\",\"QID2_TEXT\":\"\",\"QID3_TEXT\":\"\",\"QID4_TEXT\":\"\",\"QID8_TEXT\":\"\",\"QID5_TEXT\":\"10\",\"QID6_TEXT\":\"Test \",\"QID7_TEXT\":\"\"},\"labels\":{\"status\":\"Imported\",\"finished\":\"True\"},\"displayedFields\":[],\"displayedValues\":{}},

This is my code:

for (var key in GetData.responses) {
  var obj = GetData.responses[key].values;
  for (var value in obj) {
    if (obj.hasOwnProperty(value)) {
      var ObjA = (obj[key]);
      document.getElementById("container").innerHTML = ObjA;
      console.log(ObjA);
    }
  }
}

I'm trying to loop over all the objects beginning with QID1 and pull the value, but I'm missing something. As you can see from the json, there's a number of fields I need to filter out. I'm just getting stuck in the weeds.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Maybe something like following snippet (just little modification of your code):

const responses = [
  {
    values: {
      QID1_text: 1,
      QID2_text: 1212,
    }
  },
  {
    values: {
      QID1_text: 2,
      QID2_text: 1212,
    }
  },
  {
    values: {
      QID1_text: 3,
      QID2_text: 1212,
    }
  },
]
const text = document.querySelector("#container")
const regEx = /^QID1/;
for (let key in responses) {
  let obj = responses[key].values;
  for (let value in obj) {
    if (regEx.test(value)) {
      let ObjA = (obj[value]);
      let p = document.createElement("p");
      let div = document.createElement("div");
      div.setAttribute('data', ObjA);
      p.innerHTML = ObjA;
      div.appendChild(p);
      text.appendChild(div);
    }
  }
}
<p id="container"></p>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!