Store the minimum and maximum range in an object:

var a = {
    from: 0,
    to: 100
};
Answer from zero298 on Stack Overflow
🌐
Java2Blog
java2blog.com › home › javascript › create array from 1 to 100 in javascript
Create Array from 1 to 100 in JavaScript [6 Ways] - Java2Blog
December 27, 2022 - The for loop contained three expressions: the first expression is var i = 1, the second is i <= 100, and the third is i++. The first expression, var i = 1, set the value of variable i to 1 before starting the loop, and this expression got executed once.
Discussions

arrays - Does JavaScript have a method like "range()" to generate a range within the supplied bounds? - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Turn scattered docs and code into trusted AI context. Explore the new Stack Internal platform More on stackoverflow.com
🌐 stackoverflow.com
Basic JavaScript - Use Recursion to Create a Range of Numbers
Hello, I’ve just completed the Basic JavaScript portion of the JavaScript curriculum. I completed the few recursion lessons without the hints, but they’re pretty simple, considering they’re nearly identical to the example questions. I’ve watched a few youtube videos, now trying to really ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
1
0
March 31, 2023
javascript - JS loop - how can i decrement from 1 to 100 - Stack Overflow
2 How to iterate to 100 using a for or while loop and show the sum of each iteration with javascript? More on stackoverflow.com
🌐 stackoverflow.com
Number type with a specific range ([1..100] for example)
It's certainly doable, you can create a recursive type that iterates through the range and build a union. However, I would say such a type is bad practice purely for the potential performance implication - the type system was not designed for this. Just put a runtime check at the top of your function and move on with your life 😂 More on reddit.com
🌐 r/typescript
12
14
December 1, 2020
🌐
DEV Community
dev.to › ycmjason › how-to-create-range-in-javascript-539i
JavaScript Range: How to create range in Javascript - DEV Community
April 8, 2020 - We could have a more efficient way of doing this by using generators. function* range(start, end) { for (let i = start; i <= end; i++) { yield i; } } We could use this generator in a for...of loop (which would be very efficient) or use an array ...
🌐
Josh W. Comeau
joshwcomeau.com › snippets › javascript › range
Generate a "range" array in JavaScript • Josh W. Comeau
Iterating from a start value to an end value, with a given step, is exactly the problem that for loops were designed to solve.
Top answer
1 of 16
2798

Numbers

[...Array(5).keys()];
 => [0, 1, 2, 3, 4]

Character iteration

String.fromCharCode(...[...Array('D'.charCodeAt(0) - 'A'.charCodeAt(0) + 1).keys()].map(i => i + 'A'.charCodeAt(0)));
 => "ABCD"

Iteration

for (const x of Array(5).keys()) {
  console.log(x, String.fromCharCode('A'.charCodeAt(0) + x));
}
 => 0,"A" 1,"B" 2,"C" 3,"D" 4,"E"

As functions

function range(size, startAt = 0) {
    return [...Array(size).keys()].map(i => i + startAt);
}

function characterRange(startChar, endChar) {
    return String.fromCharCode(...range(endChar.charCodeAt(0) -
            startChar.charCodeAt(0), startChar.charCodeAt(0)))
}

As typed functions

function range(size:number, startAt:number = 0):ReadonlyArray<number> {
    return [...Array(size).keys()].map(i => i + startAt);
}

function characterRange(startChar:string, endChar:string):ReadonlyArray<string> {
    return String.fromCharCode(...range(endChar.charCodeAt(0) -
            startChar.charCodeAt(0), startChar.charCodeAt(0)))
}

lodash.js _.range() function

_.range(10);
 => [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
_.range(1, 11);
 => [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
_.range(0, 30, 5);
 => [0, 5, 10, 15, 20, 25]
_.range(0, -10, -1);
 => [0, -1, -2, -3, -4, -5, -6, -7, -8, -9]
String.fromCharCode(..._.range('A'.charCodeAt(0), 'D'.charCodeAt(0) + 1));
 => "ABCD"

Old non es6 browsers without a library:

Array.apply(null, Array(5)).map(function (_, i) {return i;});
 => [0, 1, 2, 3, 4]

console.log([...Array(5).keys()]);

(ES6 credit to nils petersohn and other commenters)

2 of 16
654

For numbers you can use ES6 Array.from(), which works in everything these days except IE:

Shorter version:

Array.from({length: 20}, (x, i) => i);

Longer version:

Array.from(new Array(20), (x, i) => i);​​​​​​

which creates an array from 0 to 19 inclusive. This can be further shortened to one of these forms:

Array.from(Array(20).keys());
// or
[...Array(20).keys()];

Lower and upper bounds can be specified too, for example:

Array.from(new Array(20), (x, i) => i + *lowerBound*);

An article describing this in more detail: http://www.2ality.com/2014/05/es6-array-methods.html

🌐
W3Resource
w3resource.com › javascript-exercises › javascript-conditional-statements-and-loops-exercise-7.php
JavaScript conditional statement and loops: Iterates the integers from 1 to 100 - w3resource
July 10, 2025 - ... // Loop through numbers from 1 to 100 for (var i = 1; i <= 100; i++) { // Check if the number is divisible by both 3 and 5 if (i % 3 === 0 && i % 5 === 0) { console.log(i + " FizzBuzz"); } // Check if the number is divisible by 3 else if ...
🌐
Our Code World
ourcodeworld.com › articles › read › 1486 › how-to-print-the-numbers-from-1-to-100-without-including-numbers-in-your-javascript-code
How to print the numbers from 1 to 100 without including numbers in your JavaScript code | Our Code World
April 16, 2021 - As limit, we define a numeric value that will be 10, stored in the max variable, and then we will simply multiply it by the same variable, so 10x10=100, and that's the limit of the loop.
Find elsewhere
🌐
Softuni
js-book.softuni.org › chapter-05-loops.html
5.1. Loops - Book "Programming Basics" with JavaScript
The program does not accept input and prints the numbers from 1 to 100 sequentially, each on a separate line. We can solve this problem with a for loop which will pass through the numbers from 1 to 100 using the variable i and will print the numbers in the loop's body:
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Basic JavaScript - Use Recursion to Create a Range of Numbers - JavaScript - The freeCodeCamp Forum
March 31, 2023 - Hello, I’ve just completed the Basic JavaScript portion of the JavaScript curriculum. I completed the few recursion lessons without the hints, but they’re pretty simple, considering they’re nearly identical to the exam…
🌐
Medium
medium.com › @techwithtwin › mastering-the-for-loop-in-javascript-a-beginners-guide-techwithtwin-6e12d831fd76
Mastering the for Loop in JavaScript: A Beginner’s Guide | TechWithTwin | by TechWithTwin | Medium
July 8, 2025 - const numbers = []; for (let i = 0; i <= 100; i++) { numbers.push(i); } console.log(numbers); Doing Mathematical Calculations. e.g., Sum of numbers. let sum = 0; for (let i = 1; i <= 10; i++) { sum += i; } console.log(`Total: ${sum}`); The for ...
🌐
Quora
quora.com › How-do-I-make-a-JavaScript-for-while-I-loop-to-display-integers-in-the-range-of-1-100-that-are-divisible-by-3-or-by-5
How to make a JavaScript for while I loop to display integers in the range of 1-100 that are divisible by 3 or by 5 - Quora
Answer: For Loops: They’re all fun and games til someone puts an i out By a “for while I loop”, I presume you mean a for loop or a while loop that uses i s a counter variable. By divisible “by 3 or by 5”, I presume you are referring to the classic Fizz Buzz algorithm.
🌐
Codecademy
codecademy.com › forum_questions › 51c858349c4e9dd24201011d
Print all prime number between 1 to 100 by javascript | Codecademy
... //Sets up the counter (1-100 right now) for (var counter = 1; counter <= 100; counter++) //Creates a variable called not_prime and automatically sets it to false for each of the counter numbers { var not_prime = false; //Creates a for loop ...
🌐
Jason Watmore's Blog
jasonwatmore.com › post › 2021 › 10 › 02 › vanilla-js-create-an-array-with-a-range-of-numbers-in-a-javascript
Vanilla JS - Create an array with a range of numbers in a JavaScript | Jason Watmore's Blog
October 2, 2021 - (function() { // 0 to 9 const range = [...Array(10).keys()]; document.getElementById('rangeOne').innerHTML = JSON.stringify(range); })(); (function() { // 1 to 10 const start = 1; const end = 10; const range = [...Array(end - start + 1).keys()].map(x => x + start); document.getElementById('rangeTwo').innerHTML = JSON.stringify(range); })(); (function() { // 5 to 20 const start = 5; const end = 20; const range = [...Array(end - start + 1).keys()].map(x => x + start); document.getElementById('rangeThree').innerHTML = JSON.stringify(range); })(); (function() { // 0 to 100 step 10 const start = 0; const end = 100; const step = 10; const arrayLength = Math.floor(((end - start) / step)) + 1; const range = [...Array(arrayLength).keys()].map(x => (x * step) + start); document.getElementById('rangeFour').innerHTML = JSON.stringify(range); })();
🌐
Medium
artemee-lemann.medium.com › range-function-in-javascript-b12fbff42d03
range() function in JavaScript. How many times have to been doing… | by Artemee Lemann | Medium
December 1, 2023 - Let’s create one ourselves! And use it in for loops or array creation! In JavaScript iterators are a light weight objects having a [Symbol.iterator] which allows to pull next values using .next() method which gives an object of { value: any; done: boolean }
🌐
Go Make Things
gomakethings.com › how-to-create-a-range-of-numbers-with-vanilla-js
How to create a range of numbers with vanilla JS | Go Make Things
January 13, 2021 - We can copy his code as-is for this. In it, if no max is provided, Darren reassigns the min argument to max, and sets min to 1.
🌐
W3Schools
w3schools.com › js › js_loop_for.asp
JavaScript for Loop
For Loops are fundamental for tasks like performing an action multiple times. ... const cars = ["BMW", "Volvo", "Saab", "Ford"]; let len = cars.length; let text = ""; for (let i = 0; i < len; i++) { text += cars[i]; } Try it Yourself » · exp 1 is used to initialize the variable(s) used in the loop (let i = 0).