在JavaScript中创建任意长度的零填充数组的最有效方法是什么?
ES6 introduces Array.prototype.fill .
Array.prototype.fill
(ES6引入了Array.prototype.fill 。)
(可以这样使用:)
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 .
(它仍然不在IE中( 检查兼容性 ),但是有一个polyfill可用 。)
1.4m articles
1.4m replys
5 comments
57.0k users