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

266
Visualizações
NodeJS - How do I make from python 'for _ in range(number)' in NodeJS/JavaScript

In python3x I'm using a simple code:

for i in range(1, 10):
    print(i)

I tried using Array function on NodeJS/JavaScript:

const LIST = [];
const Range = Array(10).fill("0, 10", 0, 10)
LIST.push(Range);

console.log(LIST);

But it seems it just gonna give output:

[
  [
    '0, 10', '0, 10',
    '0, 10', '0, 10',
    '0, 10', '0, 10',
    '0, 10', '0, 10',
    '0, 10', '0, 10'
  ]
]

How do I make it gives output from 1 to 10?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Why... not just use a plain for loop?

for(let i = 1; i < 10; i++) {
  console.log(i);
}
about 4 years ago · Juan Pablo Isaza Relatório

0

Array() fills the array with nothing but gives it a certain length, so filling it with null makes it [null, null, ...]. Mapping the array is similar to mapping in python, you loop through each item in the array and return the current index + 1. That creates an array [1, 2, 3, 4 ..., 10]

const Range = Array(10).fill(null).map((_, i) => i + 1);

console.log(Range);

about 4 years ago · Juan Pablo Isaza Relatório

0

The equivalent to for i in range(x, y) is for (let i = x; i < y; i++):

for (let i = 1; i < 10; i++) {
  console.log(i)
}

Output is 1, 2, 3, 4, 5, 6, 7, 8, 9 just as it was in your Python example.

See docs.

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