Skip to main content
added 78 characters in body
Source Link
Manikant Gautam
  • 3.6k
  • 1
  • 20
  • 30

You can use the spread operator on the keys of a freshly created array [...Array(n).keys()]

console.log([...Array(6).keys()]) console.log([...Array(2).keys()]) // or console.log(Array.from(Array(6).keys(), i => i+1)); console.log(Array.from(Array(2).keys(), i => i+1));

You can use the spread operator on the keys of a freshly created array [...Array(n).keys()]

console.log(Array.from(Array(6).keys())); console.log(Array.from(Array(2).keys()));

You can use the spread operator on the created array [...Array(n).keys()]

console.log([...Array(6).keys()]) console.log([...Array(2).keys()]) // or console.log(Array.from(Array(6).keys(), i => i+1)); console.log(Array.from(Array(2).keys(), i => i+1));

Source Link
Manikant Gautam
  • 3.6k
  • 1
  • 20
  • 30

You can use the spread operator on the keys of a freshly created array [...Array(n).keys()]

console.log(Array.from(Array(6).keys())); console.log(Array.from(Array(2).keys()));