Languages
[Edit]
EN

JavaScript - create array of all integers between two numbers (inclusive)

0 points
Created by:
Blessing-D
574

In this article, we would like to show you how to create an array of all integers between two numbers in JavaScript.

Quick solution:

Note:

The startNumber can't be higher than endNumer and they both have to be integers.

 

Reusable arrow function (ES6+)

Edit

In this example, we create a reusable arrow function that creates array of all integers between start and end numbers. In this solution, the start number can be higher than the end number.

 

References

Edit
  1. Array.prototype.push() - JavaScript | MDN

Alternative titles

  1. JavaScript - create array of elements between two numbers (inclusive)
  2. JavaScript - create array of elements in given range (inclusive)
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join