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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:45:45+00:00 2026-06-14T08:45:45+00:00

After reading many Stackoverflow questions, blogs, and documentation I still cannot figure out why

  • 0

After reading many Stackoverflow questions, blogs, and documentation I still cannot figure out why this particular iteration over any array is not working.

I am using jQuery and javascript(obviously) to pull a GeoJSON file and then going over the properties of the resulting object to pull desired key/value pairs. As I find those pairs I want to insert then into another array object. The object is created as I expected however when I attempt to go over the newly created object nothing happens and if I try to find its length it returns a length of 0.

This is where I pull the records:

_recordsFromGeoJSON: function(inputText) {
    var retRecords = {},

    $.getJSON(this.GeoJSONUrl, function(data) {
        var geoJSONdata = data;

        $.each(geoJSONdata.features, function(fkey, fvalue) {
            $.each(fvalue.properties, function(pkey, pvalue) {
                var re = new RegExp(inputText, "i");
                var retest = re.test(pvalue);
                if (retest) {
                    retRecords[pvalue] = fvalue.geometry.coordinates;
                    return;
                }
            });
        });
    }); 
    return retRecords;
},

This is the code for the interation over the new object:

for(var key in this._retRecords) {
        //this function will never run
        var always = foo(bar);
    }

Some sample GeoJSON:

{
"type": "FeatureCollection",                                                                           
"features": [
{ "type": "Feature", "id": 0, "properties": { "NAME": "14 PARK PLACE PH 4", "AREAID":      3.0, "STR12M": 0.0, "CLS12M": 6.0, "STR4M": 0.0, "CLS4M": 0.0, "TOTAL": 164.0, "OCC": 112.0, "NFU": 0.0, "UNC": 3.0, "DVL": 49.0, "UDVL": 0.0 }, "geometry": { "type": "Point", "coordinates": [ -93.27512816536759, 37.044305883435001 ] } }
,
{ "type": "Feature", "id": 1, "properties": { "NAME": "ALPHA MEADOWS NORTH", "AREAID": 8.0, "STR12M": 0.0, "CLS12M": 0.0, "STR4M": 0.0, "CLS4M": 0.0, "TOTAL": 12.0, "OCC": 0.0, "NFU": 0.0, "UNC": 0.0, "DVL": 0.0, "UDVL": 0.0 }, "geometry": { "type": "Point", "coordinates": [ -92.839131163095786, 37.119205483765143 ] } }
]
}

When I console.log(this._retRecords); Chrome reports shows the object with all the properties I expected from the dataset:

Object
    14 PARK PLACE PH 4: Array[2]
        0: -93.27512816536759
        1: 37.044305883435
        length: 2
        __proto__: Array[0]
    ALPHA MEADOWS NORTH: Array[2]
        0: -92.839131163095786
        1: 37.119205483765143
        length: 2
        __proto__: Array[0]

Using both methods given on this question report 0 length.

I am quite certain I am missing something fundamental but I cannot find what it is. Any help, criticism, alternative methods would be great!

  • 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-14T08:45:46+00:00Added an answer on June 14, 2026 at 8:45 am

    It appears that you don’t understand that your getJSON() function starts immediately (e.g. sends the request) and then returns immediately long before the getJSON function has completed it’s work. It’s work will be done sometime later when the completion function is called. Thus retRecords is not yet populated when the _recordsFromGeoJSON() function returns.

    This is asynchronous programming. The completion function for getJSON will be called sometime LATER, long after _recordsFromGeoJSON() returns. Thus, you cannot treat it like synchronous, serial programming.

    Instead, retRecords is only known in the completion function or in any function you pass the data to and call from that completion function. This is how asynchronous programming works in javascript. You must initiate all further processing of the getJSON() result from the completion function. And, you can’t return the result from _recordsFromGeoJSON() because the result is not yet known when that function returns. This is a different way of coding and it a bit of a pain, but it is how you have to deal with asynchronous operations in javascript.

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

Sidebar

Related Questions

After reading similar questions with many variants, I'm still stuck on this issue. Here's
I've searched StackOverflow and there are many ConcurrentModificationException questions. After reading them, I'm still
After reading many related posts on this site on the subject of image comparison
After reading many times this question and its accepted answer How to execute a
After reading many articles and some questions on here, I finally succeded in activating
After reading many questions on here, I decided to give clang a go, and
I am in a situation that I can't really resolve after reading many questions/solutions
There are already many questions raised about CSS & remaining width. After reading them
Yes I know, this question has been asked MANY times but after reading all
After reading many of the replies to this thread , I see that many

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.