0

Here is my JSON array which I need to parse using javascript code.

{ "individualTicketList": [{ "TicketID": 58, "ResponderID": 1, "Subject": "test sub", "DueByDate": "2021-10-12" }, { "TicketID": 59, "ResponderID": 1, "Subject": "test", "DueByDate": "2021-10-12" }] }

I am having an above json array and i need to display subject of each object from my json `which is inside individualticketlist  here is my code.`

for(var i=0;i<jsonString.length;i++)
{
alert(a.individualTicketList[i].DueByDate);
}

1 Answer 1

1

Here's how to loop through it

let json = {
  "individualTicketList": [{
    "TicketID": 58,
    "ResponderID": 1,
    "Subject": "test sub",
    "DueByDate": "2021-10-12"
  }, {
    "TicketID": 59,
    "ResponderID": 1,
    "Subject": "test",
    "DueByDate": "2021-10-12"
  }]
}

let arr = json["individualTicketList"]

for (var i = 0; i < arr.length; i++) {
  console.log(arr[i].Subject);
  console.log(arr[i].DueByDate);
  //your other code here
}

Sign up to request clarification or add additional context in comments.

4 Comments

Uncaught TypeError: Cannot read properties of undefined (reading 'Subject')
I am not sure how you run it. The snippet above displays the output when you run it
Yes in snippet it works fine but giving an error after integration
You need to add more details. where is your json coming from? console it before running the for loop. It could also be the json is undefined at the time when the loop runs. I can't say more without having more details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.