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

132
Vistas
how to create array from 17 to 120

what is the fastest way to create array from number 17 to number 120?

[17,18,20,...,118,119,120]

I tried to use Array method but its start with 0 and slice from some resson cut the last numbers and not the firsts numbers.

export const ARR_OF_AGES = Array(121).fill().slice(16).map((x, i) => {
  return { value: i, label: i }
})
about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

The following should work.

Array.from({length: 120 - 17 + 1}, (_, i) => i + 17)

See working example below:

const result = Array.from({length: 104}, (_, i) => i + 17)
console.log(result)

about 4 years ago · Juan Pablo Isaza Denunciar

0

If your array starts with 17 and ends with 120 it means it has 104 elements. So change 121 to 104 in your code, and instead of giving value "i" to your elements, give them value "i+17". That way your i-th element will have value i+17 meaning your array will start from 17

about 4 years ago · Juan Pablo Isaza Denunciar

0

Since you asked for "fastest", and I suggested using a for loop in the comments above, I thought that'd I'd at least give you a simple example:

let ary = [];
for (let i = 17; i <= 120; i++) {
  ary.push(i);
}

Running some simple performance tests shows that this method is over an order of magnitude faster then the result you accepted. So yeah, fast. And easy to understand.

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