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

216
Vistas
Table Numbering in ReactJS

I am coding a table with ReactJS and MUI, I want to mark the No. column from 1 to the length of the array.

This is my code:

<TableBody>
    {quizes.map((quiz) => (
      <TableRow key={quiz._id}>
        <TableCell className={s.tablecell}>{.........}</TableCell>
        <TableCell className={s.tablecell}>
          {quiz.text}
        </TableCell>
        <TableCell className={s.tablecell}>
          {quiz.answer}
        </TableCell>
        <TableCell className={s.tablecell}>
          <Button
            size="small"
            variant="outlined"
            disableElevation
            color="info"
            className={s.btn}
            onClick={nevigateUpdateQuestion}
          >
            Edit
          </Button>
          <Button
            size="small"
            variant="outlined"
            disableElevation
            color="warning"
          >
            Delete
          </Button>
        </TableCell>
      </TableRow>
    ))}
</TableBody>

I use NodeJS and MongoDB as server so I cannot use quiz._id to number the table. How can I do to mark from 1 to the length of the array? The No. cell is in {.........} section.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The second parameter of the map function is the index (0-based) of the iterating item. You can add one (index + 1) to get the 1-based number.

Try this

<TableBody>
    {quizes.map((quiz, quizIndex) => (
        <TableRow key={quiz._id}>
            <TableCell className={s.tablecell}>{quizIndex + 1}</TableCell>
            <TableCell className={s.tablecell}>{quiz.text}</TableCell>
            <TableCell className={s.tablecell}>{quiz.answer}</TableCell>
            <TableCell className={s.tablecell}>
                <Button
                    size="small"
                    variant="outlined"
                    disableElevation
                    color="info"
                    className={s.btn}
                    onClick={nevigateUpdateQuestion}
                >
                    Edit
                </Button>
                <Button
                    size="small"
                    variant="outlined"
                    disableElevation
                    color="warning"
                >
                    Delete
                </Button>
            </TableCell>
        </TableRow>
    ))}
</TableBody>
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