Skip to main content
added 192 characters in body
Source Link
mplungjan
  • 180k
  • 29
  • 183
  • 246

In ES6 you can do:

Array(N).fill().map((e,i)=>i+1);

http://jsbin.com/molabiluwa/edit?js,console

Edit: Changed Array(45) to Array(N) since you've updated the question.

console.log( Array(45).fill(0).map((e,i)=>i+1) );

In ES6 you can do:

Array(N).fill().map((e,i)=>i+1);

http://jsbin.com/molabiluwa/edit?js,console

Edit: Changed Array(45) to Array(N) since you've updated the question.

In ES6 you can do:

Array(N).fill().map((e,i)=>i+1);

http://jsbin.com/molabiluwa/edit?js,console

Edit: Changed Array(45) to Array(N) since you've updated the question.

console.log( Array(45).fill(0).map((e,i)=>i+1) );

deleted 1 character in body
Source Link
Nate
  • 6.5k
  • 3
  • 27
  • 31

In ES6 you can do:

Array(N).fill(0).map((e,i)=>i+1);

http://jsbin.com/molabiluwa/edit?js,console

Edit: Changed Array(45) to Array(N) since you've updated the question.

In ES6 you can do:

Array(N).fill(0).map((e,i)=>i+1);

http://jsbin.com/molabiluwa/edit?js,console

Edit: Changed Array(45) to Array(N) since you've updated the question.

In ES6 you can do:

Array(N).fill().map((e,i)=>i+1);

http://jsbin.com/molabiluwa/edit?js,console

Edit: Changed Array(45) to Array(N) since you've updated the question.

added 82 characters in body; deleted 10 characters in body
Source Link
Nate
  • 6.5k
  • 3
  • 27
  • 31

In ES6 you can do:

Array(45).fill(0).map((e,i)=>i+1); 

Array(N).fill(0).map((e,i)=>i+1);

http://jsbin.com/molabiluwa/edit?js,console

Edit: Changed Array(45) to Array(N) since you've updated the question.

In ES6 you can do:

Array(45).fill(0).map((e,i)=>i+1); 

http://jsbin.com/molabiluwa/edit?js,console

In ES6 you can do:

Array(N).fill(0).map((e,i)=>i+1);

http://jsbin.com/molabiluwa/edit?js,console

Edit: Changed Array(45) to Array(N) since you've updated the question.

Source Link
Nate
  • 6.5k
  • 3
  • 27
  • 31
Loading