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

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

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 Denunciar

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 Denunciar

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