Skip to content

Commit 77905d7

Browse files
committed
Add option for con-splat-enating arrays
CoffeeScript allows you to concatenate arrays by splatting them into an array literal. This change adds a section describing that option.
1 parent b128dcc commit 77905d7

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Diff for: chapters/arrays/concatenating-arrays.md

+10
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ array1
5656
# => [1, 2, 3, 4, 5, 6]
5757
{% endhighlight %}
5858

59+
A more idiomatic approach is to use the splat operator (`...`) directly in an array literal. This can be used to concatenate any number of arrays.
60+
61+
{% highlight coffeescript %}
62+
array1 = [1, 2, 3]
63+
array2 = [4, 5, 6]
64+
array3 = [array1..., array2...]
65+
array3
66+
# => [1, 2, 3, 4, 5, 6]
67+
{% endhighlight %}
68+
5969
## Discussion
6070

6171
CoffeeScript lacks a special syntax for joining arrays, but `concat()` and `push()` are standard JavaScript methods.

0 commit comments

Comments
 (0)