> Le 25 mars 2018 à 20:27, Cyril Auburtin <[email protected]> a écrit :
> 
> String and Array share a few methods.
> 
> I think `repeat` could exist for Array as well
> 
> At the moment are other more verbose ways to do so:
> 
> - `Array.from({length: n}, () => 'foo')`
> - `Array(n).fill('foo')`
> - `[].concat(...Array.from({length: 3}, () => ['x', 'y']))`
> - `[].concat(...Array(3).fill(['x', 'y']))`
> 
> so with repeat it would just be;
> 
> - `['foo'].repeat(n)`
> - `['x', 'y'].repeat(3)`

For filling a new array with one value, `Array(n).fill('foo')` seems reasonable 
to me.

Are there use cases for filling with alternating values, as in `['x', 
'y'].repeat(3)`?

—Claude
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to