--- In email@example.com
, "benxwhite" <ben.a.white@...> wrote:
> //Method 4
> var foo = ;
> foo.length = n + 1;
> foo = foo.join('*');
> Method 4 compared very similar to Method 1 in speed, and actually slightly faster. (approximately 10-40% in my tests)
> It was not the fastest in every browser, but was the most consistent in performance across browsers.
> I would suggest Method 4 for best performance, and Method 1 for cleanest.
Very interesting. I find it unintuitive how using arrays to work with strings can actually be faster than working directly with strings... yet here we are.
40% faster, you say? That's impressive, given how both appear to do exactly the same thing. It probably has to do with the fact that "new Array" does different things depending on what you pass to it.