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

185
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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