Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

417
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda