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

193
Views
Populate array with multiples of 25 up to certain limit - JS

I'm trying to create an array that will include numbers of 25 up to 300. For example:

const arr = [25, 50, 75, 100, 125...., 300];

Here's what I have so far:

var every25to300 = 300; 

for (var i = 0; i <= every25to300; i++) {
   console.log(i);
}

I've tried something like console.log(i + 25) but that starts from 25 and goes up to 325. I know I'm doing something wrong just not sure what exactly. Can I ask for some help, please?

Many Thanks!

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

0

Could use a generator, can even make the generator configurable.

function* incGenerator(start = 0, inc = 25, limit = 300) {
  let i = start;
  while (i < limit) {
    i += inc;
    yield i;
  }
  return limit;
}

const arr = [...incGenerator()];
const arr2 = [...incGenerator(50, 100, 500)];

console.log(arr);
console.log(arr2);

about 4 years ago · Juan Pablo Isaza Report

0

You can use array#from to generate your array.

const arr = Array.from({length: 12}, (_,i) => 25 + (i * 25))
console.log(arr);

You can increment in steps of 25.

const every25to300 = 300, result = [];
for (let i = 25; i <= every25to300; i += 25) {
   result.push(i);
}
console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

You need to multiply i by 25 inside the loop and divide the upper limit by 25:

var every25to300 = 300; 

for (var i = 0; i <= every25to300 / 25; i++) {
   console.log(i * 25);
}

Or alternatively, increment i by 25 on every iteration:

var every25to300 = 300;

for (var i = 0; i <= every25to300; i += 25) {
  console.log(i);
}


To construct an array, use the push() method:

const arr = [];
var every25to300 = 300;

for (var i = 0; i <= every25to300; i += 25) {
  arr.push(i);
}

console.log(arr);

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!