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

178
Vistas
make a loop of numbers in a Menu of Chakra ui in react js project

I'm trying to make a Menu list with Menu items based on the number of the stock that in the object I made , so if stock in the object is 5 , then I want the menu to give me a loop from 1 to 5 for the user to choose

 const productDetails = {
      title : "product title",
      stock : "5"
  }
  
 for (var i = 1; i <= productDetails.stock; i++) {
     console.log(i)
 }

    <MenuList>
            <MenuItem>{i}</MenuItem>
     </MenuList>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can do this using create an array of empty strings and then map over array to get the number of MenuItem as there are in productDetails.stock.

I've used index as key which is not recommended. You can use any key for each element.

  const productDetails = {
    title: "product title",
    stock: "5"
  };

  return (
    <MenuList>
      {Array(+productDetails.stock)
        .fill("")
        .map((n, i) => {
          return <MenuItem key={i}>{i + 1}</MenuItem>;
        })}
    </MenuList>
  );
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