Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

272
Views
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 answers
Answer question

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 Report

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!