Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

407
Views
How to get the length of table in javascipt(number of Rows)?
     for (let i = 0; i < 3; i++) {
          
          var z = document.getElementById("table_st").rows[i].cells;
          
      subtitles.innerHTML=subtitles.innerHTML+z[0].innerHTML+"   "+z[1].innerHTML+"   "+z[2].innerHTML+"\n";
             }

here i put <3 because i don't know the number of row that the table table_st" has

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Find no of rows and columns in a table.

let len = document.getElementById("resultsTable").rows.length;

for (let i = 0; i < len; i++) {
  var z = document.getElementById("resultsTable").rows[i].cells.length;
  console.log("Row no : ",i+1," has column : ",z)
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link
      href="https://unpkg.com/bootstrap@3.3.2/dist/css/bootstrap.min.css"
      rel="stylesheet"
    />
    <title>Document</title>
  </head>
  <body style="margin: 100px">
    <table
      id="resultsTable"
      data-tableName="Test Table 2"
      class="table table-bordered"
    >
      <thead>
        <tr class="noExl">
          <td>This shouldn't get exported</td>
          <td>This shouldn't get exported either</td>
          <td>This shouldn't get exported either</td>
        </tr>
        <tr style="background-color: #dddddd ;">
          <th>Company</th>
          <th>Contact</th>
          <th>Country</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>Alfreds Futterkiste</td>
          <td>Maria Anders</td>
          <td>Germany</td>
        </tr>
        <tr>
          <td>Centro comercial Moctezuma</td>
          <td>Francisco Chang</td>
          <td>Mexico</td>
        </tr>
        <tr>
          <td>Ernst Handel</td>
          <td>Roland Mendel</td>
          <td>Austria</td>
        </tr>
        <tr>
          <td>Island Trading</td>
          <td>Helen Bennett</td>
        </tr>
        <tr>
          <td>Laughing Bacchus Winecellars</td>
          <td>Yoshi Tannamuri</td>
          <td>Canada</td>
        </tr>
      </tbody>
      <tfoot>
        <tr>
          <td>Magazzini Alimentari Riuniti</td>
          <td>Giovanni Rovelli</td>
          <td>Italy</td>
        </tr>
      </tfoot>
    </table>
  </body>
  <script src="https://unpkg.com/jquery@3.3.1/dist/jquery.min.js"></script>
  <script src="https://unpkg.com/bootstrap@3.3.2/dist/js/bootstrap.min.js"></script>
  <script src="https://cdn.rawgit.com/rainabba/jquery-table2excel/1.1.0/dist/jquery.table2excel.min.js"></script>
</html>

about 4 years ago · Juan Pablo Isaza Report

1

To get the number of rows:

document.getElementById("table_st").rows.length;

In your example:

for (let i = 0; i < document.getElementById("table_st").rows.length; i++) {
  var z = document.getElementById("table_st").rows[i].cells;
  subtitles.innerHTML=subtitles.innerHTML+z[0].innerHTML+"   "+z[1].innerHTML+"   "+z[2].innerHTML+"\n";
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!