Sometimes, we want to generate sequence of numbers or characters in JavaScript.
In this article, we’ll look at how to generate sequence of numbers or characters in JavaScript.
How to generate sequence of numbers or characters in JavaScript?
To generate sequence of numbers or characters in JavaScript, we call the array fill
method.
For instance, we write
const chars = Array(8).fill(1);
to call Array
to create an array with 8 empty slots.
Then we call fill
with 1 to fill all the empty slots with 1’s.
Conclusion
To generate sequence of numbers or characters in JavaScript, we call the array fill
method.