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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:53:04+00:00 2026-06-15T21:53:04+00:00

My global variable ‘data’ gets a messsage: [undefined × 4] In the console log.

  • 0

My global variable ‘data’ gets a messsage:

 [undefined × 4] 

In the console log. That should be wrong as I’ve pushed 4 elements onto the array. This is the code

var data = [];

         ws.onmessage = function(evt){

         var distances = JSON.parse(evt.data);
         console.log(distances);
            for(var i=0; i<buffer.length; i++) {
                if(buffer[i][0] == distances.miles) {
                    buffer[i][1][0]++;
                    }
            }               
            console.log(buffer);

            for (var i=0; i<buffer.length; i++) { 
                data.push(buffer[i][1][0]); 
            }
            console.log(data);
            draw();//redraw the graph
            data.length=0;
        }

As you can see data should now be an array with elements.

Thanks

  • 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-15T21:53:05+00:00Added an answer on June 15, 2026 at 9:53 pm

    The console it’s a live representation of the variables in memory, and you’re invalidating the array’s contents with data.length=0;. You should try something like console.log($.clone(data)); (from jQuery) before data.length=0;.

    This is assuming that you’re absolutely sure that the data you expect really exists.

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

Sidebar

Related Questions

I have global variable fan_coil_ai_bi, and I use that variable to store some data
I have a global variable averagel that I am trying to manipulate in a
If i have global variable in A.dll, that depends on global variable in B.dll
I defined a global variable that is called from other view and it is
I have a global variable int[] and I want to clear its data and
When we should use global variable and when class variable and why? I hope
In here it's said that for global variable the following form: (1) const char
i want declare on form as global variable and then work with that in
I need a Global variable/class that stores some basic information about the currently logged
Is there any function / global variable in PHP that returns the current state

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.