- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display all the numbers from a range of start and end value in JavaScript?
Let’s say the following is our start value −
var startValue=10;
Let’s say the following is our end value −
var endValue=20;
Use the for loop to fetch numbers between the start and end value −
Example
var startValue=10; var endValue=20; var total=''; function printAllValues(startValue,endValue){ for(var start=startValue;start < endValue ;start++){ total=total+start+","; } } printAllValues(startValue,endValue) var allSequences = total.slice(0, -1); console.log(allSequences);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo87.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo87.js 10,11,12,13,14,15,16,17,18,19
Advertisements