Sam Sam - 2 months ago 7
Javascript Question

javascript - Create Simple Dynamic Array

What's the most efficient way to create this simple array dynamically.

var arr = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"];


Let's say we can get the number 10 from a variable

var mynumber = 10;

Answer
var arr = [];
for(var i=1; i<=mynumber; i++) {
   arr.push(i.toString());
}
Comments