Joined February 2013
·

D. Dotsenko

Los Angeles, California
·
·

Posted to Why never use new Array in Javascript over 1 year ago

There is one very good reason for use of new Array(length):

You want to duplicate a string multiple times. Let's say

var times = 5
var a = new Array(times + 1)
var newstring = a.join(oldstring)

^ The easiest way to produce placeholder strings of given lengths for number padding (preceeding zeros) or string padding (preceeding spaces) without needing to loop.

Daniel.

Achievements
60 Karma
0 Total ProTip Views