VOOZH about

URL: https://www.geeksforgeeks.org/jquery/create-array-of-integers-between-two-numbers-inclusive-in-javascript-jquery/

⇱ Create Array of Integers Between Two Numbers Inclusive in JavaScript/jQuery - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Create Array of Integers Between Two Numbers Inclusive in JavaScript/jQuery

Last Updated : 23 Jul, 2025

There are multiple approaches for creating an array of all integers between two numbers, inclusive, in JavaScript/jQuery. Here are some of the common methods:

Method 1: Using Loops

The for loop or while loop iterates through all the integers between the two given numbers and pushes them into an array.

Syntax:

for (statement 1 ; statement 2 ; statement 3){
 code here...
}

Example: In this example, we will see the use of for loop and push().


Output
[ 1, 2, 3, 4, 5 ]

Method 2: Using Array.from() method

Use Array.from() method to create an array of all integers between two numbers, inclusive.

Syntax:

function createArray(start, end) {
 return Array.from({length: end - start + 1}, 
 (_, index) => start + index);
}

Example: In this example, we will see the use of Array.from() method.


Output
[ 1, 2, 3, 4, 5 ]

Method 3: jQuery approach using for loop

The program starts by defining the start and end of the numeric range as start and end respectively, which in this case are set to 3 and 9. By using a map we iterate between the number and get the value.

Output:

👁 Create array of all integers between two numbers, inclusive, in JavaScript/jQuery
Create an array of all integers between two numbers, inclusive, in JavaScript/jQuery
Comment

Explore