Most efficient way to create a zero filled JavaScript array?

ES6 introduces Array.prototype.fill. It can be used like this:

new Array(len).fill(0);

Not sure if it’s fast, but I like it because it’s short and self-describing.

It’s still not in IE (check compatibility), but there’s a polyfill available.

Leave a Comment