This post will discuss how to create an array sequence from 1 to N in JavaScript.

There are several ways to create an array sequence of integers from 1 (inclusive) to N (inclusive), where the value N is dynamic.

1. Using Array.from() function

Download  Run Code

 
Or use Array Constructor

Download  Run Code

Or

Download  Run Code

2. Using Spread operator

Download  Run Code

or

Download  Run Code

or

Download  Run Code

3. Using Underscore Library

Download Code

 
The _.range method is overloaded to generate a range from start (inclusive) to stop (exclusive), incremented (or decremented) by step.

Download Code

That’s all about creating an array sequence from 1 to N in a single line in JavaScript.