I've seen this pattern on CodePen:
var demo = new Array(3);
demo = demo.join(' ').split(' ');
Can someone please explain me this pattern?
Is it just for getting an array with n empty-strings? Or does it target something else?
The CodePen in which I've seen it:
http://codepen.io/pavlovsk/pen/wWVqaq
Please see Function nJoin() .
It's just to create an array with empty strings. Note that, with es6, you can make this more easy and more readable by using Array.prototype.fill instead:
var a = new Array(3).fill("");
console.log(a); // ["", "", ""]
See the browser support table, it's a new feature at the time of this writing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With