Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

137
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda