JavaScript fill array with incrementing numbers/integer | Example code

Use loop to fill array of numbers 1…n in JavaScript. First create an empty array with length then use loop and store the every value one by one in the Array.

JavaScript fill array with incrementing numbers

HTML Example code of JavaScript array containing 1 through to N where N is up to.

If don’t want to store anything in the array, use a container with the right length that you can iterate over.

Store value in Array

Output: Filling a array with 1 to 10 number by increasing it 1.

JavaScript fill array with incrementing numbers

Print value 1 to 10

Output:

JavaScript fill array with incrementing numbers example html

Do comment if you have another example or doubts or suggestion on this topic.

Note: All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.