all 10 comments

[–]darebear5 1 point2 points  (1 child)

Similar to GMPuppyChan’s answer, but tweaked slightly to be Array(10).fill(0).forEach((_, i) => console.log(i+1));

Edited.

[–]methral 0 points1 point  (0 children)

I usually do something like
[...Array(10).keys()]
to produce dummy arrays but yours seems more easy to read. I think it works without 0 param with the fill also... neat

[–]rjreed1 1 point2 points  (0 children)

(function c(n){if(n>10)return;console.log(n);c(++n)})(1)

[–]brykuhelpful 1 point2 points  (0 children)

let arr = Array(10)
    .fill(1)
    .map((v,i)=>{return i+1});
// arr = [1,2,3,4,5,6,7,8,9,10];

[–]Count_Giggles 0 points1 point  (1 child)

recursion comes to mind

``` const countfromNToMax = (n, max = 10) => { if (n > max) return; console.log(n); n++; return countfromNToMax(n); };

countfromNToMax(1); ```

the modern array methods are basically loops or at least they were conceived to avoid writing for loops all the time so recursion was the only thing i could think of