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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T19:29:35+00:00 2026-06-17T19:29:35+00:00

I have made an array that is used to loop through a table (initially

  • 0

I have made an array that is used to loop through a table (initially hidden) and display certain rows depending on which section is requested:

var rows_per_section = [ {min: 0, max: 7}, {min: 7, max: 17}, {min: 17, max: 21}, {min: 21, max: 35}, {min: 35, max: 41}, {min: 41, max: 46}, {min: 46, max: 52},{min: 52, max: 56} ];
var rows_min = rows_per_section[section_no].min;
var rows_max = rows_per_section[section_no].max;

I am now trying to alter the script with an extra function that cycles through the table and creates the rows_per_section array on its own as the length of the table can be varied. I can detect the breaks in the table by looking for a class tag but I cannot figure out how to create the array and add new values every time it hits a break:

function create_section_array(profile_table, no_of_sections) {
    var section_counter = 0;
    var rows_per_section = new Array();    //this is where it starts to go wrong
                                           //need to create the array and stick in the
                                           //MIN value for the first section as 0
    for (i=0;i<profile_table.length-1;i++) {
        var table_row = profile_table.item(i);
        var row_content = table_row.getElementsByTagName("td");
        if(row_content[0].className == "ProfileFormTitle") {
            if(section_counter != 0) {
                //if not the first section add a MAX value to
                //rows_per_section[section_counter + 1]
            }
            if(section_counter != no_of_sections) {
                //if not the last section add a MIN value to
                //rows_per_section[section_counter]
            }
            section_counter++;
        }
    }
    return rows_per_section;
}
  • 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-17T19:29:37+00:00Added an answer on June 17, 2026 at 7:29 pm

    I would modify your function to look something like this:

    function create_section_array (profile_table, no_of_sections) {
        var section_counter = 0,
            rows_per_section = [ { min: 0 } ],
            precedingLength = 0,
            i, row_content;
    
        for (i = 0; i < profile_table.length; i += 1) {
            row_content = profile_table[i].getElementsByTagName('td');
    
            if (row_content[0].className === 'ProfileFormTitle') {
                if (section_counter !== 0) {
                    rows_per_section[section_counter] = {
                        max: row_content.length - 1
                    };
                }
    
                if (section_counter !== no_of_sections) {
                    rows_per_section[section_counter].min = precedingLength;
                }
    
                section_counter += 1;
                precedingLength += row_content.length;
            }
        }
    
        return rows_per_section;
    }
    

    A few notes on the above:

    • i was not explicitly declared originally, meaning it existed globally. I’ve added the declaration.

    • There is no block scope in JavaScript, only function scope (vars are hoisted). I’ve moved the declaration of row_content to the top of the function as that is the prevalent idiomatic style.

    • The operators == and != perform type coercion. It is generally safer to stick to === and !== instead.

    • You can declare arrays with literal syntax, there’s no need for new Array(). In your case, we initialise using [ { min: 0 } ] to set up the basic required structure, but more commonly you see people initialise with the empty array, [].

    • Likewise, when setting the value of new indices in the array, we can use literal object syntax for the basic required structure. In your case, this is { max: row_content.length - 1 }.

    • Technically, this isn’t a multi-dimensional array, it is an array of objects (or dictionaries, maps, key/value stores, whatever you want to call them).

    • I haven’t actually run the above and only have a vague sense of the context to your problem. There may be (are probably?) issues with this code! 🙂

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

Sidebar

Related Questions

I have made an app that gets an array of addresses from a web
I have an array that I want on multiple pages, so I made it
PHP: I have made up a function that returns an array. I would like
I have an array that's made up of data returned by a SQL query:
I have an array of strings that are supposed to be used as constraints
I have made a helper class called Navigation that gets used on every page
I have made a String[] array by using String.split(.) . I am now trying
I have an array made of unlimited number of objects. These objects have the
So i have 2 classes, users and health readings. i made a array of
I have a 2d array grid made as int GRID[10][20]; What I want to

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.