Creating a filled array with a given length?

Axel Rauschmayer axel at rauschma.de
Tue Dec 11 22:59:21 PST 2012


I would still love to have something like that in ES6 (loosely similar to String.prototype.repeat). Once you have that, you can e.g. use Array.prototype.map to do more things.

Two possibilities:
- Array.repeat(undefined, 3) -> [ undefined, undefined, undefined ]
- [ undefined ].repeat(3) -> [ undefined, undefined, undefined ]

The same array could be created like this, but that seems too much work for a relatively common operation.

'x'.repeat(3).split('').map(=> undefined)

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20121212/9df88365/attachment.html>


More information about the es-discuss mailing list