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

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

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 Report

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 Report

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