Categories
JavaScript Answers

How to generate sequence of numbers or characters in JavaScript?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *