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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:38:13+00:00 2026-06-07T08:38:13+00:00

I have an array of data that has been collected by iterating through an

  • 0

I have an array of data that has been collected by iterating through an existing table as such:

    ---------------
    Mon | Hot  | 12 
    ---------------
    Tue | Cold | -2 
    ---------------
    Wed | Warm | 3  
    ---------------
    Thu | Cold | -4 
    ---------------
    Fri | Cold | -3 
    ---------------

The data in the array is stored as such: [‘Mon’, ‘Hot’, ’12’, ‘Tue’, ‘Cold’, ‘-2’ .. etc ..]

The data now needs to be displayed in a table that has flipped the rows and columns, so that the data is shown as follows:

Mon | Tue  | Wed  | Thu  | Fri
-------------------------------
Hot | Cold | Warm | Cold | Cold
-------------------------------
12  | -2   | 2    | -4   | -3

I am struggling to find the right loop statements to print the data correctly.

So far I have the following:

for (i = 0; i < weather_data.length; i++)
{                                                        
    if (i%5==0)
    {
        table.push('<tr><td>'+weather_data[i*3]+'</td>');
    }
    else if(i%4==0)
    {
        table.push('<td>'+weather_data[i*3]+'</td></tr>');
    }
    else
    {
        table.push('<td>'+weather_data[i*3]+'</td>');
    }
}

Which correctly displays the top line, but the rest is all undefined because the called indexes are too large for the array obviously. I have worked out the the 2nd row needs to call the following index: ((index-5)*3)+1, but the 3rd row is going to require a different index call too.. there must be an equation that will work for all rows.. this must be a fairly common operation!

The resultant table needs to show indexes in the following order:

0   3   6   9   12
1   4   7   10  13
2   5   8   11  14

So the loop needs to generate these in order of left to right, then next row etc.

~It also needs to added the necessary starting <tr> and </tr> tags respectively.

  • 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-07T08:38:14+00:00Added an answer on June 7, 2026 at 8:38 am
    var data = ['Mon', 'Hot', '12', 'Tue', 'Cold', '-2', 
                'Wed', 'Warm', '3', 'Thu', 'Cold', '-4'];
    var width = 3;
    var height = data.length / width;
    var r = "";
    for(var i = 0; i < width; i++) {
      var row = [];
      for(var j = 0; j < height; j++) {
        row.push("<td>" + data[j * width + i] + "</td>");
      }
      r += "<tr>" + row.join("") + "</tr>";
    }  
    
    $("#container_id").html("<table>" + r + "</table>");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys, I have a Table View that has been populated with 21 data:
I have a php array that has a bunch of data that I need
I have a massive multidimensional array that has been serialised by PHP. It has
I have an array that has been built and passed into actionscript from javascript.
I have a model that I'm trying to retrieve an array of data from,
I have an accordion that binds data for each item from an array. I
I have a variable that contains an array from form data, seen below: $option1
Hey, I've got a PHP file that that echo's an array that has been
Have data that has this kind of structure: $input = [ { animal: 'cat',
I want to be able to store (not echo) some data that has been

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.