Most efficient way to create a zero filled JavaScript array?

前端 未结 30 1193
花落未央
花落未央 2020-11-22 05:58

What is the most efficient way to create an arbitrary length zero filled array in JavaScript?

30条回答
  •  渐次进展
    2020-11-22 06:23

    Using lodash or underscore

    _.range(0, length - 1, 0);
    

    Or if you have an array existing and you want an array of the same length

    array.map(_.constant(0));
    

提交回复
热议问题