Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8086827
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:34:09+00:00 2026-06-05T18:34:09+00:00

I am trying to use for..in loop to access the description key/value within ‘Event’

  • 0

I am trying to use for..in loop to access the description key/value within ‘Event’ but at the moment am not fully sure how to achieve this. First of all I used the for..in and logged this out, this returns all the top level entries in the response, how do I now drill down and pick out Event.description? I first of all thought it was data[prop].Event.description but thats not the case. Should I be using a normal for loop and then the for..in inside of this?

Here is my current code:

$(document).ready(function() {

    var data = {
        "status": "ok",
        "code": "200",
        "message": "event details",
        "data": [{
            "Event": {
                "id": "1",
                "name": "Sample Event Number 1",
                "description": "Sample Event Number 4 Description ....",
                "event_date": "2012-05-31 00:00:00",
                "Band": [{
                    "id": "1",
                    "name": "Support #1",
                    "BandsEvent": {
                        "id": "7",
                        "band_id": "2",
                        "event_id": "8",
                        "created": "2012-05-23 15:53:56",
                        "modified": "2012-05-23 15:53:56"
                    }},
                {
                    "id": "2",
                    "name": "Support #2",
                    "BandsEvent": {
                        "id": "8",
                        "band_id": "1",
                        "event_id": "8",
                        "created": "2012-05-23 15:53:57",
                        "modified": "2012-05-23 15:53:57"
                    }}]
            }},
        {
            "Event": {
                "id": "2",
                "name": "Sample Event Number 2",
                "description": "Sample Event Number 4 Description ....",
                "event_date": "2012-05-31 00:00:00",
                "Band": [{
                    "id": "2",
                    "name": "Another Crazy Band",
                    "BandsEvent": {
                        "id": "3",
                        "band_id": "2",
                        "event_id": "8",
                        "created": "2012-05-23 15:53:56",
                        "modified": "2012-05-23 15:53:56"
                    }},
                {
                    "id": "4",
                    "name": "The Band",
                    "BandsEvent": {
                        "id": "8",
                        "band_id": "1",
                        "event_id": "8",
                        "created": "2012-05-23 15:53:57",
                        "modified": "2012-05-23 15:53:57"
                    }}]

            }}]
    }


    var prop;

    for (prop in data) {
        console.log( data[prop] );
        // data.Event.description 
    }

});​
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T18:34:11+00:00Added an answer on June 5, 2026 at 6:34 pm

    This should do what you want:

    for (var i = 0; i < data.data.length; i++) {
        console.log(data.data[i].Event.description);        
    }
    

    I should add that the reason that your code doesn’t work is that the “prop” variable would first be “status“, then “code“, then “message” and THEN “data“. Status/code/message has no “Event” property, so therefore your code would return undefined if you’d try to access data[prop].Event. Here we pick them out specifically. And since that data.data is an array, there’s no reason to use a for .. in loop, but rather just a regular for loop.

    Likewise, if you would want to print out the descriptions AND the bands, you could do the following:

    for (var i = 0; i < data.data.length; i++) {
        console.log(data.data[i].Event.description + " has the following bands:"); 
        for (var j = 0; j < data.data[i].Event.Band.length; j++) {  
            console.log(data.data[i].Event.Band[j].name); 
        }       
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a cursor loop in MYSQL, but it's not working. I've
I'm trying to use for..in loop to select the objects within a variable and
I'm trying to use the foreach loop in an Ant script but I get
I was trying to use a multiple value in a for loop. if I
I am trying to access the $Frined_Id outside the while loop. But it is
I'm trying to use Linq to loop through all fonts in the %windir%\Fonts folder
I'm trying to use a foreach loop for an array of objects. Inside of
I'm trying to use openmp to multithread a loop through std::set. When I write
I'm trying to use a for line in data: loop to assign the first
I was trying use svn to find a checkin using svn log, but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.