0

how creating a JavaScript array containing 1 through to x where x is only known at runtime without the loop.

var arr = [];

for (var i = 1; i <= x; i++) {
   arr.push(i);
}
Leo Lucas
  • 3
  • 4

1 Answers1

0

This is a duplicate of this issue

here is the answer anyway

const arr = [...''.padEnd(N)].map((_,i)=>i+1)
Bobby Morelli
  • 460
  • 2
  • 7
  • Once you've reached 3k rep, you can vote to close as duplicate. For now, this should be a comment. – 0stone0 Jan 31 '23 at 17:04