The XMLHttpRequest only retrieves up to 32 descendant objects from the JSON file, not all of them

I've encountered a peculiar issue with my XMLHttpRequest and JSON file. While I can successfully access the data, it seems to only iterate through 32 child objects within each parent object.

Take, for example, this snippet from the routes.json file:

{
  "Routes": [
    {
      "name": "Route 1",
      "locations": [
        {
          "Name": "ABC Store",
          "Address": "123 W 456 S"
        },
        {
          "Name": "XYZ Store",
          "Address": "321 E 654 N"
        },
        {
          ... (66 other locations)
        }
      ]
    },
    {
      ... (more routes)
    }
  ]
}

My main index.php file calls this data using an XMLHttpRequest. However, when looping through the locations of each route, it stops at 32 iterations. Here's a snippet of the code:

var request = new XMLHttpRequest();
request.open("GET", "routes.json", false);
request.send(null);
var route_data = JSON.parse(request.responseText);

var allRoutes = route_data.Routes;

for (var key1 in allRoutes) {

  var locations = allRoutes[key1].locations;
  for (var key2 in locations) {
    //I forgot to put this line in, and it was causing the problem
    if (!allRoutes.hasOwnProperty(key2)) continue;

    // Repeat the Route Name for each location to get a count
    console.log("Route Name: "+allRoutes[key1].Name);
    // Repeats only 32 times max when there are really 66+ in most of them

  }

}

Does JavaScript impose a limit on the number of iterations when looping through arrays or objects retrieved via XMLHttpRequest?

Answer №1

There is absolutely no limit to parsing, it can go on indefinitely.

Feel free to check out this fiddle

Take a look at the sample data that matches your format

https://api.myjson.com/bins/8w3bs

If you check the console, you will see the loops printing properly even with more than 32 items.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Decode JSON and generate a user-friendly Array

My aim is to extract and organize the JSON data received from an external API into a custom array. However, I am encountering two challenges: I'm struggling to access the value labeled #2 under "Meta Data". If I want to extract the first array n ...

Retrieving the ID and value of a specific dropdown list using jQuery from an array of dropdown lists

My HTML structure looks like this: <?php foreach($active_brand as $brand) { ?> <select name="selector" id="selector"> <?php foreach($options as $option) { ?> <option <?php if($brand['State'] == $option) { ?& ...

Convert TypeScript-specific statements into standard JavaScript code

For my nextjs frontend, I want to integrate authentication using a keycloak server. I came across this helpful example on how to implement it. The only issue is that the example is in typescript and I need to adapt it for my javascript application. Being u ...

Tips for stopping Vue.js automatic merging of CSS classes

Recently, I embarked on my journey with Vue.js and have been thoroughly enjoying the experience. However, I've stumbled upon a challenge that has me stumped. Despite searching high and low and studying the documentation, I haven't found a solutio ...

Executing a Drupal rule using JavaScript: A step-by-step guide

I'm facing a challenge when trying to activate a Drupal rule using JavaScript code. lowerLayer[image.feature_nid].on("dragend", function() { var position = kineticImage.getPosition(); var layerPosition = this.getPo ...

Experiencing the issue with the $.getJSON function bug

Is there a way to ensure that my code processes the $.getJSON function fully? I am encountering an issue where only the first alert, 'inside1', is triggered when running the site. The second alert, 'inside x2', never gets processed. Any ...

Encountering a Typescript error while attempting to remove an event that has a FormEvent type

Struggling to remove an event listener in Typescript due to a mismatch between the expected type EventListenerOrEventListenerObject and the actual type of FormEvent: private saveHighScore (event: React.FormEvent<HTMLInputElement>) { This is how I t ...

Utilize JSON to populate ImageAdapter with images

Hey there! I recently tried out a GridView demo from this link The demo worked perfectly, but now I'm looking to retrieve images from a server database. To achieve this, I implemented a handler class that interacts with the server and retrieves image ...

Unable to redirect with Asp response.redirect

I have a Login popup form where I use an ajax post request to Login.asp script in order to prevent the page from going to the POST URL after submission. <script> $(function() { $('#contactForm').submit(function(e){ e.preventDe ...

Looking for a resolution with NicEditor - Seeking advice on incorporating custom select options

I recently started using NICInline Editor and found a helpful sample at Is there a way to incorporate custom options into this editor? I would like the selected option's value to be inserted right at the cursor point of the Editor Instance. Query: H ...

Organizing identical array elements in PHP participants into groups

I created a function to detect word sequences: function checkSequence($arrScheme = [], $arrInput = []) { $sequenceNeeded = array_values(array_intersect($arrScheme, $arrInput)); if(!empty($arrInput) && ($sequenceNeeded == $arrIn ...

Display time series data from PHP by utilizing Flot Charts in jQuery

After receiving data from a database, which is formatted using PHP and returned as a JSON response for an Ajax call, I encountered an issue. Everything works fine and the data is plotted except when the X-Axis contains dates, in which case nothing gets plo ...

What is the best way to output the leaf nodes from an array of object lists in TypeScript?

Having trouble with TypeScript, specifically working with arrays and filtering out leaf nodes. I want to print only the leaf nodes in the array, resulting in ['002', '004', '007']. Can someone please assist me? Excited to lear ...

Creating a New Line in JSON Format Using Flask Python and Displaying it as HTML

I've been struggling to properly format JSON with new lines, but all my attempts have failed. from flask import * import json app = Flask(__name__) @app.route("/user/", methods=["GET"]) def user(): datajson = {"Author&q ...

The beauty of Angular.js filters lies in their ability to create nested

I'm currently working on developing a straightforward pagination filter for Angular, which can be implemented as shown below: <ul> <li ng-repeat="page in items | paginate: 10"> <ul> <li ng-repeat="item in p ...

Once invoked by an ajax request, the $().ready function is executed

The functionality of this code is flawless when running on its own. However, once I make an ajax call to it, the code fails to execute. I suspect that the issue lies within $().ready, but I haven't yet identified a suitable replacement. Any suggestio ...

Increasing several array elements within a MongoDB object

I have been struggling with this problem for some time now. My goal is to update multiple array values in the same object with a single query. The data in the database appears as follows: id: 616f5aca5f60da8bb5870e36 title: "title" recommendations: ...

What is the best way to reload scripts each time a component is mounted?

My jQuery scripts include animation effects that need to be refreshed whenever something new is rendered on the page. However, I am facing an issue where the jQuery scripts are not being refreshed as needed. Below is my router configuration: export defau ...

What is the best way to incorporate Javascript into jQuery tabs?

On my website, I have implemented a Jquery and CSS tab system similar to the one found here. Each tab contains a Facebook feed box, a Twitter widget, and a ranking widget for my blog. However, when these widgets are placed within the tab content area, they ...

When navigating through a view in backbone.js, ensure to include an argument in the routing process

Looking to include an argument while routing within a Backbone.js application Below is the script: var AppRouter = Backbone.Router.extend({ routes: { 'toolSettings/(:action)' : 'toolSettings' } }); var initialize = function ...