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

220
Views
How do I populate angularjs list with for loop or array?

I have the following code someone hard coded:

$scope.years = [
   {id:curryear, name: curryear}
   {id:curryear - 1, name: curryear - 1}
   {id:curryear - 2, name: curryear -2}
];

My task is to populate it so that the HTML dropdown it is linked to can get every year within a certain range. I am pretty new to using angularjs so I am not sure about what I can do with it. Is there a way to iterate through the range, lets say 2020 to 2010 while populating it? Or can I make an array of sets in the JS function this resides in and set $scope.years equal to that>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

For example you want to start from 2020 and you want to go till 2010:

const years = [{id: 2020, name: 2020}];
for ( let i = 1; i <= 10; i++ ) {
    years.push({id: years[i-1].id - 1, name: years[i-1].name - 1});
 }
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!