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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:31:21+00:00 2026-05-22T16:31:21+00:00

I have created a table using a for loop in my code and have

  • 0

I have created a table using a for loop in my code and have various variables in multiple arrays. I want to be able to put the values from the array individually into each table cell going down in a column. For code I have this:

function tableCreate() {
 for (rownum = 1; rownum <= 7; rownum++) {
     document.write("<tr>");
     for (colnum = 1; colnum <= 7; colnum++) {  
     if (rownum == 1 + colnum == 1) {
         document.write("<td>" + id[0] + "</td>");
     }
     }
     document.write("</tr>");
 }
}

var id = new Array("1022", "1112", "1230", "554", "1355", "1600");
var title = new Array("Prof.", "Prof.", "Prof.", "Prof.", "Asst. Prof.", "Asst. Prof.");
var name = new Array("Catherine Adler", "Michael Li", "Maria Sanchez", "Robert Hope", "Wayne Li", "Kate Howard");
var position = new Array("Department Chair", "Asst. Chair", "TA Supervisor");
var er = new Array(2, 3, 1, 2, 1, 3);
var yoe = new Array(18, 12, 10, 23, 8, 5);
var cs = new Array(85000, 70000, 62000, 55000, 50000, 45000);

The above code is all part of an external JavaScript document. I tryed using if statements to produce what I wanted but that failed. Now I’m lost and some help would be appreciated. To reitterate, I want to get say this array: var id = new Array(“1022”, “1112”, “1230”, “554”, “1355”, “1600”);

into a table column and have each variable in that array take a cell in that column.

  • 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-05-22T16:31:21+00:00Added an answer on May 22, 2026 at 4:31 pm

    Not so clear but I think what you want is this:

    function tableCreate() {
     for (rownum = 1; rownum <= 7; rownum++) {
         document.write("<tr>");
         for (colnum = 1; colnum <= 7; colnum++) {  
           if (colnum == 1) {
             document.write("<td>" + id[(colnum-1)] + "</td>");
           }
         }
         document.write("</tr>");
     }
    }
    

    I expect this is really what you want:

    // constants
    var colCount=7;
    var rowCount=7;
    
    // input data
    var id = new Array("1022", "1112", "1230", "554", "1355", "1600");
    var title = new Array("Prof.", "Prof.", "Prof.", "Prof.", "Asst. Prof.", "Asst. Prof.");
    var name = new Array("Catherine Adler", "Michael Li", "Maria Sanchez", "Robert Hope", "Wayne Li", "Kate Howard");
    var position = new Array("Department Chair", "Asst. Chair", "TA Supervisor");
    var er = new Array(2, 3, 1, 2, 1, 3);
    var yoe = new Array(18, 12, 10, 23, 8, 5);
    var cs = new Array(85000, 70000, 62000, 55000, 50000, 45000);
    
    // make a special column.
    var complicatedName;
    for(index = 0; index < rowCount;index++)
    {
       complicatedName[index] = title[index]+' '+name[index]+' - '+position[index];
    }
    colCount = colCount - 2
    
    // create the column array.
    var collist = [id,complicatedName,er,yoe,cs];
    
    // make the table.
    function tableCreate() {
     for (rownum = 1; rownum <= rowCount; rownum++) {
         document.write("<tr>");
         for (colnum = 1; colnum <= colCount; colnum++) {  
             document.write("<td>" + (collist[(colnum-1)])[(rownum-1)] + "</td>");
         }
         document.write("</tr>");
     }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created one table using the below command: create table Table1( Id int
I have created a table in my application, I want to select (change background
I have created a table in postgreSQL. I want to look at the SQL
I have a list of values I want to insert into a table via
I have to create one table using XSLT and CSS. The table should look
I have created a MySQL database using MySQL Workbench. It has about 20 tables.
We have created a table with a trigger that updates a ModifiedDate field in
I have Created a table like CREATE TABLE [dbo].[tab1]( [Id] [int] NOT NULL, [Name]
I have created a table on an Oracle 10g database with this structure :
I have created a table in my Ruby on Rails application that I am

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.