Is there a Javascript equivalen of Perl's qw() method to quickly create arrays ? i.e.
in Perl @myarray = qw / one two three /;
in Javascript var myarray = ('one', 'two', 'three' ); // any alternative??
To ‘quickly’ write an array, you can do this:
var x = 'foo bar baz'.split(' ');
Especially for large arrays, this is slightly easier to type than:
var x = ['foo', 'bar', 'baz'];
Although obviously, using .split()
is much less performant than just writing out the entire array.
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