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

162
Views
Accessing nested endpoints inside a loop NodeJS

I am trying to add some links to a list of items. The list is made using a for loop.

for(i=0;i<links.length;i++){
<li>
<a href = "<%=links[i].path%>" > ListItem </a>
</li>
}

working fine with some of the links but others are nested links , like /path1/path2

How can I add such links using the for loop?

Edit: Links are from this array

const links = [
  {
    link: "/product1",
    title: "A",
  },
 {
    link: "/product2",
    title: "A",
  },
 {
    link: "/product3",
    title: "A",
  },
 
];

Paths are defined like this

function router (lists){
Product1Router.get('/',function(req,res){

    productdata.find() 
    .then(function (products) {

    res.render('products',{
        products,
        lists
    });

    })
})
return products1Router;
}

But the problem is unable to access list item 3, which is prod/path2, while the fr loop only adds /path2

function router (lists){
    Product2Router.get('/',function(req,res){

    productdata.find() 
    .then(function (products) {

    res.render('products',{
        products,
        lists
    });

    })
})

Product2Router.get('/path2',function(req,res){
    res.render('addNew',{
        lists
    });

});


return products1Router;
}
about 4 years ago · Juan Pablo Isaza
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!