Skip to content
Advertisement

How to generate sequence of numbers/chars in javascript?

Is there a way to generate sequence of characters or numbers in javascript?

For example, I want to create array that contains eight 1s. I can do it with for loop, but wondering whether there is a jQuery library or javascript function that can do it for me?

Advertisement

Answer

You can make your own re-usable function I suppose, for your example:

JavaScript

Then you could do either of these:

JavaScript

You can give it a try here, note the above example doesn’t rely on jQuery at all so you can use it without. You just don’t gain anything from the library for something like this 🙂

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement