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 6323499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:31:46+00:00 2026-05-24T16:31:46+00:00

Server returns to the client this JSON: { comments: [ { id: 99, entryId:

  • 0

Server returns to the client this JSON:

{
    "comments": [
        {
            "id": 99,
            "entryId": 19,
            "author": "Вася",
            "body": "Комент Васи",
            "date": "20.10.2022"
        },
        {
            "id": 100,
            "entryId": 19,
            "author": "n54",
            "body": "w754",
            "date": "21.10.2023"
        }
    ],
    "admin": false
}

I am trying to show out it:

if (xmlhttp.readyState==4 && xmlhttp.status==200){
    var json = eval("("+xmlhttp.responseText+")");
    for(var comment in json.comments){
        alert(comment["author"]);
    }
}

As expected, cycle works 2 times, but this alert shows only “undefined”.
But if I try to execute alert(json.admin); it will show false, as planned.
What am I doing wrong?

  • 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-05-24T16:31:47+00:00Added an answer on May 24, 2026 at 4:31 pm

    If you have to iterate over the contents in the array you should iterate over the array indexes rather than iterate over the properties in the array,

    So use the following code snippet to iterate over the array indexes which is the right thing to do,

    for(var i = 0; i < json.comments.length; i++){
        alert(json.comments[i]["author"]);
    }
    

    Iterating over array properties like the following code snippet is not the right way because one of the array properties contains ‘remove’ function.

    for(var i in json.comments){
        alert(json.comments[i]["author"]);
    }
    

    In the above code i will take values 0, 1, 2,…, remove function

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

Sidebar

Related Questions

I'm using Apache HttpComponents Client to POST to a server that returns JSON. The
I return this json from the server: { Id: 0, Name: ko.observable('New Product'), PurchasePrice:
My AJAX-enabled WCF service returns JSON using this contract, [DataContract] public class JQGridContract {
We know that MVC returns DateTime for JsonResult in this format: /Date(1240718400000)/ , and
I have config.time_zone in environment.rb set to UTC, and my mySQL server returns the
I have an HTTP server that returns large bodies in response to POST requests
From one apache server file_get_contents returns the contents of a url straight away. On
On my Centos server Python's mimetypes.guess_type(mobile.3gp) returns (None, None), instead of ('video/3gpp', None). Where
Is the following possible in SQL Server 2000? CREATE FUNCTION getItemType (@code varchar(18)) RETURNS
I'm developing an application for a client's website. Here's the story, this company uses

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.