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

179
Views
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 answers
Answer question

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 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!