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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:38:04+00:00 2026-06-02T04:38:04+00:00

Based on chrome developer tools a breakpoints I think I’m dealing with a scope

  • 0

Based on chrome developer tools a breakpoints I think I’m dealing with a scope issue I can figure out. Is it the way I define the function? The script below is an include js file and the array ‘ timeStamp I want available for use in other functions without having to call my loadData function everytime.

The timeStamp array goes undefined once it leaves the for loop before it even leaves the function.

var timeStamp = [];  // Want this array to be global

function loadData (url){

        $.getJSON(url, function(json) {

            for (var i=0;i<json.length;i++){
                    timeStamp.push(json[i].TimeStamp);  
                }
                    console.log(inputBITS); //returns the value
            });
        console.log(inputBITS); //undefined
        }

Thank you for anyhelp

  • 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-02T04:38:05+00:00Added an answer on June 2, 2026 at 4:38 am

    It looks like the issue is that getJSON is asynchronous. When it executes and finishes and your code continues on, it indicates only the START of the networking operation to retrieve the data. The actual networking operation does not complete until some time later.

    When it does complete, the success handler is called (as specified as the second argument to your getJSON() call) and you populate the timeStamp array. ONLY after that success handler has been called is the timeStamp array valid.

    As such, you cannot use the timeStamp array in code that immediately follows the getJSON() call (it hasn’t been filled in yet). If other code needs the timeStamp array, you should call that code from the success handler or use some other timing mechanism to make sure that the code that uses the timeStamp array doesn’t try to use it until AFTER the success handler has been called and the timeStamp array has been populated.

    It is possible to make some Ajax calls be synchronous instead of asynchronous, but that is generally a very bad idea because it locks up the browser during the entire networking operation which is very unfriendly to the viewer. It is much better to fix the coding logic to work with asynchronous networking.

    A typical design pattern for an ajax call like this is as follows:

    function loadData (url){
    
        $.getJSON(url, function(json) {
            // this will execute AFTER the ajax networking finishes
            var timeStamp = [];
            for (var i=0;i<json.length;i++) {
                    timeStamp.push(json[i].TimeStamp);  
            }
            console.log(timeStamp);
            // now call other functions that need timeStamp data
            myOtherFunc(timeStamp);
         });
         // this will execute when the ajax networking has just been started
         //
         // timeStamp data is NOT valid here because 
         // the ajax call has not yet completed
         // You can only use the ajax data inside the success handler function
         // or in any functions that you call from there
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When debugging browser-based apps using Google Chrome's Developer Tools, is there a way to
Looking into Chrome Developer Tools' Audits tab when launching my Vaadin-based web application, I
I think Chrome OS is based on Linux and written in C/C++. I haven't
I've encountered a random issue in Webkit based browsers (tested in Chrome and Safari).
Is there a good resource on using console of Google chrome developer tools. I
Based on http://alexreg.wordpress.com/2009/05/03/strongly-typed-csv-reader-in-c/ , I created a DLL which can read different file types.
I port a Chrome extension to Firefox. Because the XUL-based API is quite different
I want to write a Chrome extension that intercepts some data that a Javascript-based
I'd like to write a Chrome extension that works with a particular JS-based chat
Facebox is a jQuery-based, Facebook-style lightbox which can display images, divs, or entire remote

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.