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

  • Home
  • SEARCH
  • 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 8471769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T16:53:11+00:00 2026-06-10T16:53:11+00:00

I have data that php returned to JS but i dunno how to loop

  • 0

I have data that php returned to JS but i dunno how to loop it to access the information… i have this:

    result = call_data('get_chat.php');
            console.log(result);
    for(var data in result){

        alert(result[data]["id"]); //says undefined

    }

Console Log shows:

   [{"eventtime":"0000-00-00 00:00:00","message":"test2","bywho":"dave","id":"2"},
    {"eventtime":"0000-00-00 00:00:00","message":"testttt","bywho":"dave","id":"1"}]  

So i want to loop each data from it but how do i do it im really confused!! It just says undefined each time.

  • 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-10T16:53:12+00:00Added an answer on June 10, 2026 at 4:53 pm

    If typeof result === "string", then you still need to parse the response before you can iterate over it:

    result = JSON.parse(call_data('get_chat.php'));
    

    Then, as others have pointed out, you should use a simple for loop with Arrays:

    for (var i = 0, l = result.length; i < l; i++) {
        console.log(result[i]["id"]);
    }
    

    for..in loops will iterate all enumerable keys rather than just indexes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code works when I have data rows returned for the messages object but
I have a PHP loop that adds data into a table cell. However, I
I have a PHP loop that adds data into a table cell. However, I
I have a php array that has a bunch of data that I need
I have a php script that inserts data from an Android app into a
I have a PHP script that grabs data from an external service and saves
I have a simple php page that displays data from a mysql database. I
First I have a PHP file that gets data and file from a HTML
I have a written a script in PHP that reads from data from a
i have a PHP contact form that submits data, and an email...: <?php $dbh=mysql_connect

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.